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

If your version of Mercurial is new enough, I believe you should be able to use the hg unamend command from the uncommit extension that ships with Mercurial. This may require that obsolescence markers are enabled, I'm not sure.

  1. Enable the uncommit extension, add this to your ~/.hgrc:

    [extensions]
    uncommit =
    
  2. Actually run the unamend:

    hg unamend
    

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).

Tags:

Mercurial