Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit Mercurial commit message after branching?

I have some old commit messages in a Mercurial repository that should be changed (to adjust for some new tools). I already understand that this hacking has to be done on the master repository and all local repositories would have to be re-cloned, because checksums of all subsequent changesets will also change.

I've tried following the recipes in "How to edit incorrect commit messages in Mercurial?", but with MQ extension I got stuck on error message

X:\project>hg qimport -r 2:tip
abort: revision 2 is the root of more than one branch

and with Histedit quite similarly

X:\project>hg histedit 2
abort: cannot edit history that would orphan nodes

The problem seems to be that there have been branches created after the changeset.

I can see how it would become messy if I'd want to change the contents of patch, but perhaps there's a workaround that I've missed for editing the commit message?

like image 934
Imre Avatar asked Nov 17 '11 02:11

Imre


People also ask

How do I edit all commit messages?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit. You can add a co-author by adding a trailer to the commit.

How do you Uncommit Mercurial?

A simple way to 'uncommit' your last commit is to use hg strip -r -1 -k. In case the link breaks, the documentation mentioned by @phb states: hg rollback Roll back the last transaction (DANGEROUS) (DEPRECATED) Please use 'hg commit --amend' instead of rollback to correct mistakes in the last commit.

How can I delete last commit in Mercurial?

If you are still in the draft phase (not pushed elsewhere yet), use the built-in extension hg strip <rev> command. Otherwise, you should do a hg backout , which will reverse the changeset. In case you still need the commit you made, I suggest you export it to import it again in the correct branch, before stripping.

How do you use a hg strip?

hg strip [-k] [-f] [-B bookmark] [-r] REV... The strip command removes the specified changesets and all their descendants. If the working directory has uncommitted changes, the operation is aborted unless the --force flag is supplied, in which case changes will be discarded.


2 Answers

I would use a hacked version of the convert extension to do this. The extension can do hg → hg conversions which lets you alter author and branch names. There is not support for changing commit messages yet, but you can hack it.

Specifically, you should change the getcommit method from:

def getcommit(self, rev):
    ctx = self.changectx(rev)
    parents = [p.hex() for p in self.parents(ctx)]
    if self.saverev:
        crev = rev
    else:
        crev = None
    return commit(author=ctx.user(), date=util.datestr(ctx.date()),
                  desc=ctx.description(), rev=crev, parents=parents,
                  branch=ctx.branch(), extra=ctx.extra(),
                  sortkey=ctx.rev())

which is responsible for reading the old commits. Change the

desc=ctx.description()

to

desc=adjust(ctx.description())

and then implement the adjust function at the top of the file:

def adjust(text):
    return text.upper()
like image 175
Martin Geisler Avatar answered Oct 13 '22 00:10

Martin Geisler


If these are accidental/duplicate branches due to using --amend and push --force then strip them first and try 'histedit' again then wipe the central repo on bitbucket; try the following which worked for me:

Inspect the repository log and look for branches, you can use the GraphlogExtension which you will have to enable first:

# hg log -G | more
...
o  changeset:   43:c2fcca731aa5
|  parent:      41:59669b9dfa4a
|  user:        Daniel Sokolowski (https://webdesign.danols.com)
|  date:        Tue Aug 27 20:14:38 2013 -0400
|  summary:     Progress snapshot: major content text and model instance  ..
...
| o  changeset:   42:c50724a6f1c6 
|/   user:        Daniel Sokolowski (https://webdesign.danols.com)
|    date:        Tue Aug 27 20:14:38 2013 -0400
|    summary:     Progress snapshot: major content text and model instance ...
|
o  changeset:   41:59669b9dfa4a
|  user:        Daniel Sokolowski (https://webdesign.danols.com)
...

Enable the MqExtension and strip all branches.

# hg strip --no-backup 42:c50724a6f1c6
# hg strip --no-backup 45:3420dja12jsa
...

If needed change the commit to 'draft' (see Phases) and re-run 'histedit' and all should be good now.

# hg histedit 14:599dfa4a669b
abort: cannot edit immutable changeset: b7cfa2f28bde
# hg phase -f -d 14:599dfa4a669b
# hg hsitedit 14:599dfa4a669ba
like image 44
Daniel Sokolowski Avatar answered Oct 12 '22 23:10

Daniel Sokolowski