views:

296

answers:

1

Let's say branch B is a topic branch off of branch A, and you want those changes in branch C. What does it mean when you cherry-pick the merge commit of branch A and branch B to branch C?

For example, if you use the -m flag to specify the old HEAD of branch A to cherry-pick the merge to branch C, does that simply mean "Take the diff between the cherry-picked commit tree and old HEAD of branch A and apply it to branch C?"

Are there any gotchas for using this method? (e.g. Would branch C look like it's merged to branch A and B? Would more changes be applied than simply the commits from branch B?)

+2  A: 

The way I usually do this is using git rebase:

git rebase --onto C A B

This takes the diffs between A and B, and applies those diffs to branch C. As a bonus, the rebase will skip any commits between A and B that perform the same textual change as already exists in branch C.

Update: In the case you mentioned in the comments, remember that Git never overwrites past history. So even after doing the rebase above, you could recreate a new branch head at the commit where B used to be before the rebase. Unfortunately I can't think of a simple way to do that at this time of the morning. Sorry I couldn't be more help, perhaps somebody else will come up with an easy way!

Greg Hewgill
Sorry, I left out that I wanted the changes in branch B to be applied to both A and C. The rebase would cause the changes in B to be easily merged with C, but now A is in the situation that C was in. Anything I can do to have those changes in A as well?
Readonly
I'm also sorry that I chose such poor branch names when posing the question :(
Readonly