Robz
Robz

Reputation: 1757

Mercurial: How to revert a commit after amending it

I ran hg commit --amend to amend a commit, but now I want to go back to the commit before I amended it. The commit hash of the commit before the amend does not appear to show up in hg log. So how do I do this?

Upvotes: 3

Views: 1877

Answers (2)

John Jefferies
John Jefferies

Reputation: 1216

If you enable the evolve extension, changesets that did get removed with "hg commit --amend" no longer get overwritten. Instead they are hidden with obsolesence markers, but can still be viewed and restored to a normal changeset.

To view hidden changesets from the command line, just add --hidden to a normal command, e.g. "hg glog --hidden -l 10". In tortoise, the filter toolbar (^S) has an icon that displays hidden changesets.

Evolve isn't yet part of the official mercurial but is due to become so. [As you see, it is supported by tortoise already.] I have been using it for ages and it works very well. It's much easier than scrabbling around trying to find an old bundle that's been given an obscure name from a date that you can't remember any more. The full history is all there in your local repo.

Upvotes: 4

zerkms
zerkms

Reputation: 254886

commit --amend command creates a backup in the .hg/strip-backup directory.

So what you need to do now is to perform

hg unbundle .hg/strip-backup/<your-backup-name>

Where <your-backup-name> is the name of backup is the one that was told you when you performed amend.

After you do that - the original changes are re-applied to the original root and you may strip whatever you don't need anymore.

Upvotes: 1

Related Questions