hg transplant

Ever wanted to cherry-pick a set of patches from one Hg branch to another one, even a set which are non-contiguous and are in the middle of the history? You need the Transplant Extension. It ships with Mercurial. Enable it in your ~/.hgrc as explained in the above-linked page. Then:

  • Get a working copy of the target branch (e.g. using hg update -C <target branch>)
  • hg log -b <source branch> to find the revision numbers of the revisions you want
  • hg transplant -b <source branch> REV1 REV2 REV3 REV4
  • hg outgoing shows the transplanted changesets
  • hg push

It’s that easy :-)

3 thoughts on “hg transplant

  1. I simply do “hg export REV | hg import -“, the result seems to be the same. But you probably need this in your hgrc file:

    [diff]
    git = true

    Not sure about the current release but Mercurial’s default exports used to contain no data on binary changes, they were also inconsistent about moves for example.

  2. IIRC at one time if you set git=true you could do binary changes but file moves would not work. But if you set git=false, file moves would work but binary changes would go down a black hole. I believe that this is fixed in current versions of Mercurial.

    Phil

Leave a Reply

Your email address will not be published. Required fields are marked *