Posts Tagged ‘mercurial’

Changing a Mercurial Commit Message After Merging

Posted in Uncategorized on March 25th, 2011 by ataylor284 – Comments Off on Changing a Mercurial Commit Message After Merging

A nice part of using a DVCS like mercurial is you have a chance to review your changes, including merges, locally before pushing them out to the world. If you do “branchy” development, it’s easy to notice a mistake in a local revision that’s already been merged with remote changes.

This stackoverflow post covers the tricks for editing a mercurial changeset message with the histedit or mq extensions. Unfortunately, they don’t work very smoothly if you’ve already merged. histedit fails if you have any commits after your merge. qimport can’t import merges or their parents.

The solution, using mercurial queues, is:

  • hg qimport all the revisions newer than the merge and qpop them
  • hg strip the merge revision – caution: this discards any changes made during the merge; if they are significant, you may want to use --keep
  • now, with the merge gone, you can either hg histedit or hg qimport and fix the message

To get back to the original state, two more steps are needed:

  • hg merge to re-merge the the branches
  • hg qpush and hg qfinish on any revisions before the merge you imported in the first step

Voila. Commit message fixed. Of course, the usual changing history is bad disclaimer applies.