Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hg Merge specific commit from another branch

Tags:

mercurial

I have two branches Dev and Feature1. I was working on Feature1, creating said feature, and committed it. I then wrote the code for Feature2 but committed it under Feature1 branch instead of a new branch (Feature2). So now i have two features in Feature1 branch as two separate commits, but I only want to include the second feature back into Dev.

What is the mercurial way to do this?

like image 630
Davis Dimitriov Avatar asked Sep 27 '11 17:09

Davis Dimitriov


2 Answers

Use hg 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'.

Documentation: https://www.mercurial-scm.org/repo/hg/help/graft

like image 157
allanlaal Avatar answered Sep 28 '22 00:09

allanlaal


  1. Supposed you have not yet published your commits:

    If you want to merge the commit Feature2 independent of commit Feature1, you should move it on its own branch.

  2. If already published:

    Use the transplant extension to "duplicate" the Feature2 commit and put it on its own branch. Then backout Feature2 commit on the Feature1 branch. Now you merge Feature2 independent of Feature1 too.

In any case, instead of putting Feature2 on its own branch, you could also put it directly onto your Dev branch if this is your actual intention.

like image 34
Oben Sonne Avatar answered Sep 28 '22 01:09

Oben Sonne