Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retroactive named branching in Mercurial

Is there a way to associate a bunch of Mercurial changesets with a named branch after they have been committed, i.e. retroactively ?

like image 263
gsakkis Avatar asked Mar 01 '10 09:03

gsakkis


2 Answers

I just wanted to do this, and here’s the solution I found. A year has passed since the question was originally asked, this might explain why I can now find a solution. It has the disadvantage that you create an extra revision in the process, but this wasn’t too bad for me.

First, you go back to where you want to create the branch. In my case, I actually wanted to start a new root (because I wasn’t very sensible when I started the repository, but anyways), so I’m updating to null. You probably want to start somewhere else, it depends on your situation.

$ hg update null

Then, create the branch.

$ hg branch blah
$ hg commit -m "Created blah branch."

Then, we rebase all the commits we made onto our new branch:

$ hg rebase -s SOURCE -d DEST

The SOURCE here should be the first commit you made in the commits you want to create the branch from, and the DEST should be the commit where the branch was created (the one we committed above).

like image 117
flowblok Avatar answered Nov 11 '22 05:11

flowblok


No, branch names are part of the changeset (it's really like a label you add to the commit), it means the changeset hash depens on the branch name.

So the only way to change it retroactively is by rewriting history (which doesn't play well if you pushed your changes elsewhere, since you'll have to rewrite every repo which has the changes).

To rewrite history, you could use for example mq.

like image 22
tonfa Avatar answered Nov 11 '22 04:11

tonfa