简体   繁体   中英

Cherry-pick a merge

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? (eg 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?)

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM