Merge selected changes from one branch to another in Mercurial

Is it possible to merge a series of changes from one branch to another in Mercurial?

eg.

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

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

Such a merger can be trivial, for example, if r5 changed files that do not change in 6 and 7 (and therefore its changes, if they are not needed, can be safely ignored)

How about a few selected change ranges from branch A to branch B? For example, a merger of 4-7, 20-25 and 30-34?

(this is not a real case, just an illustration. I'm trying to figure out if hg has this version range merge function that I know svn has)

+7
branch merge mercurial
source share
2 answers

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

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

+9
source share

The simple answer is no .

This is contrary to the spirit of Mercurial.

Your graph means that 6 depends on 5 , so anything that pulls 6 should pull 5 , otherwise it doesn't make sense.

It seems to me that you have Mercurial here. If your change tree is linear, it is usually a sign that you are using Mercurial, as if you were using CVS or SVN.

Your change tree should look larger:

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

And then you can pull either a branch starting at 5 or one that starts at 23 .

Now the error is human, so there is an β€œobject” called export that allows you to create a simple diff file from one set of changes.

In your particular case, you should:

  • clone storage to r4
  • create diff from r6 and one from r7 (export)
  • apply both (in order) to the new clone (import)
  • run your unit tests until they pass
  • commit
  • draw in r41
  • mergers
  • run your unit tests until they pass
  • commit

If you want, you can also go along the extended road. There are several useful extensions for managing change sets. Set of samples:

Here you can, for example, clone the repository (importantly, always check them on clones, just in case), and then collapse the ranges of interest to you. Then you can export / import them.

+7
source share

All Articles