11

Consider I have the following situation:

I have a branch br_foo from revision 4. After that there are 3 more changes made on default branch: 6, 7 and 8. I'd like to only merge changes 7 and 8 to br_foo. Is there a way to achieve this in mercurial?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
lang2
  • 11,433
  • 18
  • 83
  • 133

2 Answers2

11

Graft v Transplant

Depending on which version of Mercurial you are using, you will probably use either the new Graft functionality in Mercurial 2.x or the older Transplant Extension for earlier versions of Mercurial.


The Graft command

This was announced recently (Nov 2011) so I haven't had a chance to work with it myself.

This command uses Mercurial's merge logic to copy individual changes from other branches without merging branches in the history graph. This is sometimes known as 'backporting' or 'cherry-picking'. By default, graft will copy user, date, and description from the source changesets.


The Transplant Extension

I've used it for just this scenario. A little snippet from the description ...

This extension allows you to transplant patches from another branch or repository.

It records the original changeset ID in the transplanted changeset, and avoids transplanting previously-transplanted patches.

It can also be used to rebase a branch against upstream changes (including dropping changesets that have been adopted upstream), to rewrite changesets and to cherrypick some changesets.

Community
  • 1
  • 1
Chris McCauley
  • 25,824
  • 8
  • 48
  • 65
  • 1
    If you're using the new 2.0 version of Mercurial, the graft command serves exactly the same purpose and is included by default. The link for the documentation of graft is at the top of the Transplant wiki page. – krtek Dec 02 '11 at 13:03
2

Since mercurial 2.0 (released on November 1st 2011) this is handled by the new core command graft:

This command uses Mercurial's merge logic to copy individual changes from other branches without merging branches in the history graph. This is sometimes known as 'backporting' or 'cherry-picking'.

See also this other question.

Community
  • 1
  • 1
Wim Coenen
  • 66,094
  • 13
  • 157
  • 251