Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merging selected revisions from one branch on another in Mercurial

Is it possible to merge a range of revisions from one branch to another in Mercurial?

e.g.

|r1
|r2
|r3
|\___
|    | r5
|    | r6
|    | r7
|    | ...
|    | r40
|r41  

If I want to merge revisions 6 & 7, but not 5, into the main branch - is this possible?

Such a merge can be trivial, for example, if r5 modified files that are not modified in 6 & 7 (and so its changes, if not needed, can safely be ignored)

What about multiple selected revision ranges from branch A to branch B? e.g. merge 4-7, 20-25 and 30-34?

(this isn't a real case, just an illustration. I'm trying to understand if hg has this revision-range merge feature that I know svn has)

like image 391
Assaf Lavie Avatar asked Apr 02 '10 16:04

Assaf Lavie


2 Answers

Check out the Transplant extension for mercurial, I think it will do exactly what you want.

https://www.mercurial-scm.org/wiki/TransplantExtension

like image 184
Nate Heinrich Avatar answered Oct 02 '22 07:10

Nate Heinrich


The simple answer is no.

This is contrary to the spirit of Mercurial.

Your graph implies that 6 depends upon 5 so anything that pulls 6 should pull 5 also otherwise it makes no sense.

It seems to me that you got Mercurial wrong here. If your change tree is linear, it's usually a sign that you are using Mercurial like you would use CVS or SVN.

Your change tree should look more like:

   4
  / \
 /| |\
/ | | \
5 7 23 \
| | |   25
6 8 24  |
        26

And then you could pull either the branch starting at 5 or the one starting at 23.

Now, mistake is human, so there is a "facility" called export, which allow you to create a simple diff file from one changeset.

In your specific case, you would thus:

  • clone the repository up to r4
  • create a diff from r6 and one from r7 (export)
  • apply both (in order) on the new clone (import)
  • run your unit tests until they pass
  • commit
  • pull in r41
  • merge
  • run your unit tests until they pass
  • commit

If you wish, you can also go the extension road. There are several useful extensions for manipulating the changesets. A sample set:

  • Rebase
  • Collapse

Here you could for example clone the repository (important, always test these on clones, just in case) and then collapse the ranges you are interested in. Then you can export/import them.

like image 43
Matthieu M. Avatar answered Oct 02 '22 06:10

Matthieu M.