I am currently using TortoiseHg (Mercurial) and accidentally committed an incorrect commit message. How do I go about editing this commit message in the repository?
You can rollback the last commit (but only the last one) and then reapply it.
Other than that, you cannot change the repository's history (including commit messages), because everything in there is check-summed. The only thing you could do is prune the history after a given changeset, and then recreate it accordingly.
None of this will work if you have already published your changes (unless you can get hold of all copies), and you also cannot "rewrite history" that include GPG-signed commits (by other people).
Well, I used to do this way:
Imagine, you have 5 commits, and your erroneous commit message is in r.3.
hg qimport -r 3:tip
hg qpop -a
joe .hg/patches/3.diff
(change the comment, after the mercurial header)
hg qpush -a
hg qdelete -r qbase:qtip
Rollback-and-reapply is realy simple solution, but it can help only with the last commit. Mercurial Queues is much more powerful thing (note that you need to enable Mercurial Queues Extension in order to use "hg q*" commands).
I did it this way. Firstly, don't push your changes or you are out of luck. Grab and install the collapse extension. Commit another dummy changeset. Then use collapse to combine the previous two changesets into one. It will prompt you for a new commit message, giving you the messages that you already have as a starting point. You have effectively changed your original commit message.
As others have mentioned the MQ extension is much more suited for this task, and you don't run the risk of destroying your work. To do this:
- Enable the MQ extension, by adding something like this to your hgrc:
[extensions] mq =
- Update to the changeset you want to edit, typically tip:
hg up <rev>
- Import the current changeset into the queue:
hg qimport -r .
- Refresh the patch, and edit the commit message:
hg qrefresh -e
- Finish all applied patches (one, in this case) and store them as regular changesets:
hg qfinish -a
I'm not familiar with TortoiseHg, but the commands should be similar to those above. I also believe it's worth mentioning that editing history is risky; you should only do it if you're absolutely certain that the changeset hasn't been pushed to or pulled from anywhere else.