Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting linear history into two branches in Mercurial

Tags:

mercurial

I have a mercurial repository history that looks like this :

A -> B -> C -> N1 -> N2 -> N3 -> D -> E -> F

And I would like to transform it into the following history :

A -> B -> C -> D -> E -> F
           \_ N1 -> N2 -> N3

Given that I have a clone whose history stops at C, what is the best way to proceed ? D E F changeset is not conflicting with N1 N2 N3 changeset. Well, at least I hope so ;)

like image 561
shodanex Avatar asked Feb 22 '23 04:02

shodanex


1 Answers

No need to have a clone, you can work in the original repo. You can transplant D, E and F on top of C, creating copies D1, E1 and F1 (which will be identical to the originals, provided that there are no conflicting changes). You'll have this:

A -> B -> C -> N1 -> N2 -> N3 -> D -> E -> F
           \_ D1 -> E1 -> F1

Then you can strip the originals. See the script below.

$ hg update C
$ hg transplant D E F
$ hg strip D

You'll have to enable two extensions: transplant and mq. To do this, add these lines to your hgrc:

[extensions]
transplant=
mq=

Update: As of Mercurial 2.0, graft (a built-in command) can be used instead of transplant here; rebase, as Laurens Holst suggests, should work equally well.

like image 132
Helgi Avatar answered Mar 03 '23 21:03

Helgi