Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: roll back an "hg commit --amend".

Tags:

mercurial

I accidentally did a "hg commit --amend" instead of just a commit. How can I roll back the commit to before the amend?

like image 693
Don P Avatar asked May 22 '13 16:05

Don P


People also ask

How do I revert a commit in Mercurial?

If you want to revert just the latest commit use: hg strip --keep -r . Using strip will revert the state of your files to the specified commit but you will have them as pending changes, so you can apply them together with your file to a new commit.

What is HG amend?

hg amend [OPTION]... [ FILE]... aliases: refresh. combine a changeset with updates and replace it with a new one. Commits a new changeset incorporating both the changes to the given files and all the changes from the current parent changeset into the repository.


1 Answers

You can use hg reflog (from the journal extension) and hg reset <hash>.

hg reflog -v 

should give something like:

<old-hash> -> <new-hash> <user> <timestamp>  commit --amend <some-path> 

if that is the amend you want to revert, just use:

hg reset <old-hash> 

The commit will be reverted to what is previously was and the changes that were amended should now be uncommitted changes (check using hg status and hg diff).

like image 121
Sorina Sandu Avatar answered Sep 21 '22 09:09

Sorina Sandu