Mercurial: how to amend the last commit?

With the release of Mercurial 2.2, you can use the --amend option with hg commit to update the last commit with the current working directory

From the command line reference:

The –amend flag can be used to amend the parent of the working directory with a new commit that contains the changes in the parent in addition to those currently reported by hg status, if there are any. The old commit is stored in a backup bundle in .hg/strip-backup (see hg help bundle and hg help unbundle on how to restore it).

Message, user and date are taken from the amended commit unless specified. When a message isn’t specified on the command line, the editor will open with the message of the amended commit.

The great thing is that this mechanism is “safe”, because it relies on the relatively new “Phases” feature to prevent updates that would change history that’s already been made available outside of the local repository.

Leave a Comment