shodanex
shodanex

Reputation: 15406

Splitting linear history into two branches in 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 ;)

Upvotes: 4

Views: 176

Answers (2)

Helgi
Helgi

Reputation: 5436

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.

Upvotes: 6

Laurens Holst
Laurens Holst

Reputation: 21026

You can use rebase for this:

hg rebase --source D --dest C

This works as of Mercurial 2.0; previously, it used to complain when rebasing onto an ancestor revision, but they removed that.

You have to enable the rebase extension, if you haven’t already:

[extensions]
rebase =

Upvotes: 2

Related Questions