Mercurial: How do you roll back changes?

When using Mercurial, how do you undo all changes to the working directory since the last commit? It seemed like it would be easy, but it eluded me.

For example, suppose I have 4 commits. Then I make some changes to my code. Then I decide that my changes are bad, and I just want to return to the state of the code the last time I committed it. So, I think I should do:

hg update 4 

at the same time 4 is a revision No. of my last fixation. But Mercurial does not change any of the files in my working directory. Why not?

+50
version-control mercurial
Jul 09 2018-10-09T00:
source share
4 answers

hg revert will do the trick.

He will return you to the last fixation.

--all will return all files.

See the link for a description of his page.

hg update usually used to update your working directory after you pull it from different repo or swap sections. hg up myawesomebranch . It can also be used to revert to a specific version. hg up -r 12 .

+79
Jul 09 '10 at 15:25
source share

An alternative solution for hg revert is hg update -C . You can undo your local changes and upgrade to some version with this single command.

I usually prefer to print hg up -C because it is shorter than hg revert --all --no-backup :)

+16
Jul 10 '10 at 14:01
source share

hg revert is your friend:

 hg revert --all 

hg update combines your changes with the current working copy with the target revision. Merging the latest version with your modified files (= current working copy) leads to the same changes that you already have, i.e. Doing nothing: -)

If you want to read Mercurial, I would recommend a very cool Hg Init tutorial.

+6
Jul 09 2018-10-10T00:
source share
 hg revert --all 

and then

 hg pull -u 

works for me

+1
Jan 30 '13 at 2:49
source share



All Articles