Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: How do you undo changes?

When using Mercurial, how do you undo all changes in the working directory since the last commit? It seems like this would be a simple thing, but it's escaping me.

For example, let's say 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 go back to the state of the code at my last commit. So, I think I should do:

hg update 4 

with 4 being the revision # of my latest commit. But, Mercurial doesn't change any of the files in my working directory. Why not?

like image 916
Johnny Beegood Avatar asked Jul 09 '10 15:07

Johnny Beegood


People also ask

How do I revert changes in Mercurial?

Revert changes already committed To backout a specific changeset use hg backout -r CHANGESET . This will prompt you directly with a request for the commit message to use in the backout. To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.

How do you undo a pull in Mercurial?

There is only one level of rollback, and there is no way to undo a rollback. It will also restore the dirstate at the time of the last transaction, losing any dirstate changes since that time. This command does not alter the working directory.

What is backout in Mercurial?

Backout works by applying a changeset that's the opposite of the changeset to be backed out. That new changeset is committed to the repository, and eventually merged.


1 Answers

hg revert will do the trick.

It will revert you to the last commit.

--all will revert all files.

See the link for the Man Page description of it.

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

like image 96
Paul Nathan Avatar answered Oct 13 '22 01:10

Paul Nathan