2.8. Backing out a change

Mistakes happen. When they do, you need to correct them, and there are 2 ways to do this:

This is a classic "oops" case, maybe you realised just after you committed that you forgot to add a file or forgot to remove some test code, or similar. Provided you haven’t pushed the change to anyone else, you can just undo it:

hg rollback

This removes the last commit and puts the changes from it back in your working directory, ready to be committed again. You can actually keep calling this to roll back multiple commits, but bear in mind that it will just merge the changes into your working copy, meaning you’ll probably create a single commit to replace it.

If a change has already left your local repository, or if it’s buried a few levels down in the history, then you will want to undo it in a new commit that reverses the changes. You do this using the "backout" command:

hg backout -m "Backed out silly mistake in X" REV

Notice how this commits the reversal automatically (which is why a message is included).