views:

4624

answers:

6

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?

+13  A: 

I think this is what you are looking for.

lpfavreau
+25  A: 

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

Thilo
Thanks, your solution to rollback and reapply is much more simpler.
maxyfc
just for reference, the command is `hg rollback'
Valters Vingolds
I just watched a guy get a commit toasted because he followed this advice. When suggesting someone use `rollback` please always include a warning that it permanently removes the latest commit (or pull). So if you've done a `hg update` (like he had) and that commit is no longer in your working directory then it's gone forever.
Ry4an
+10  A: 

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
Antonio Beamud
You can also edit the commit message with `hg qrefresh -e` after using `hg qpop` to arrive at the right patch.
Martin Geisler
Of course instead of 'joe' you can use any other editor of choice.
Kees de Kooter
+1 this is the approach I use when I cant use the simple rollback. Windows users should note that notepad isnt happy about the eol in the diff file.
mizipzor
+3  A: 

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

Anton N. Petrov
A: 

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.

jls
+1  A: 

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:

  1. Enable the MQ extension, by adding something like this to your hgrc:
    [extensions]
    mq =
    
  2. Update to the changeset you want to edit, typically tip:
    hg up <rev>
    
  3. Import the current changeset into the queue:
    hg qimport -r .
    
  4. Refresh the patch, and edit the commit message:
    hg qrefresh -e
    
  5. 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.

Dan Villiom P. Christiansen