樱桃选择合并 [英] Cherry-pick a merge

查看:116
本文介绍了樱桃选择合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设分支B是分支A以外的主题分支,并且您希望分支C中发生这些更改。当您选择分支A和分支B的合并提交到分支C时,这意味着什么?



例如,如果使用-m标志指定分支A的旧HEAD以将樱桃挑选到分支C,那么这是否意味着樱桃挑选的提交树和分支A的旧HEAD并将其应用于分支C?



使用此方法是否有任何问题? (例如,分支C看起来像是合并到分支A和B上吗?会比应用分支B提交更多的更改吗?)

我通常这样做的方式是使用 git rebase

  git rebase --onto CAB 

这将A和B之间的差异,并将这些差异应用于分支C.作为奖励,rebase将跳过A和B之间的任何提交执行与分支C中已经存在的相同的文本更改。

更新:如果您在评论中提到过,请记住Git不会覆盖过去的历史记录。因此,即使在完成上述的rebase之后,您可以在B用于rebase之前的提交中重新创建新的分支头。不幸的是,我不能想到在这个早晨的这个时候做一个简单的方法。对不起,我没有更多的帮助,也许别人会想出一个简单的方法!


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

解决方案

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!

这篇关于樱桃选择合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆