Git樱桃选择语法和合并分支 [英] Git cherry-pick syntax and merge branches
问题描述
$ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0
错误:提交a8c5ad438f6173dc34f6ec45bddcef2ab23285e0是合并但没有-m选项被给出。
致命:樱桃挑选失败
这看起来错了.......它应该是:
$ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0
从何时开始我必须提供-m函数?
您必须提供 -m
,如果提交是一个合并提交,即提交有多个父代。
通常情况下, git cherry-pick REV
确实可以描述为:
-
在 rev 和它的父项之间进行更改。
-
将这些更改应用到当前的HEAD并用 rev 的提交信息提交结果。
Take the changes between rev and its parent.
Apply these changes to the current HEAD and commit the result with rev's commit message.
合并提交将两个发展线。例如,一行实现小部件,另一行消除混乱。
现在考虑樱桃挑选过程的第1步:git无法猜测您是否想要删除混乱或实现小部件。你也不能这样做,因为关于如何做到这一点的信息不包含在单个合并提交中,只有合成树合并的内容是。
-m
选项允许你告诉git如何继续。例如,如果在 master
上发生混乱删除,并且使用 git merge WIDGET
创建合并提交,则 git cherry-pick -m 1 merged-commit
会樱桃选择新的小部件,因为合并树和父代1(最后一个除杂提交)之间的差异将完全是小部件添加。另一方面, git cherry-pick -m 2 merge-commit
会删除混乱,因为parent 2(最后一个widget添加提交)和 merge-commit 恰恰是从 widget 分支中缺少的混乱删除。
So I have done countless cherry picks before and it seems that I must fail at life with this right now, I am trying to cherry pick from one branch to another which should be easy, how ever I get an error about it being a merge but not -m was given?
$ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0
error: Commit a8c5ad438f6173dc34f6ec45bddcef2ab23285e0 is a merge but no -m option was given.
fatal: cherry-pick failed
That looks wrong.......it should be:
$ git cherry-pick a8c5ad438f6173dc34f6ec45bddcef2ab23285e0
Since when do I have to supply a -m function?
You have to supply -m
if the commit is a merge commit, i.e. a commit with more than one parent.
Normally, what git cherry-pick REV
does can be described as:
A merge commit joins two lines of development. For example, one line implements widget, and the other line removes clutter. The merge gives you the code with the widget, sans the clutter.
Now consider step #1 of the cherry-pick process: git can't guess whether you want to remove the clutter or to implement the widget. Nor can you do both, because the information on how to do both is not contained inside a single merge commit, only the content of the resultant merged tree is.
The -m
option allows you to tell git how to proceed. For example, if clutter removal happened on master
and the merge commit was created using git merge WIDGET
, then git cherry-pick -m 1 merged-commit
will cherry-pick the new widget because diff between the merged tree and parent 1 (the last of clutter-removing commits) will have been exactly the widget addition. On the other hand, git cherry-pick -m 2 merge-commit
will delete the clutter, because the difference between parent 2 (the last of the widget-adding commits) and merge-commit is exactly the clutter-removal missing from the widget branch.
这篇关于Git樱桃选择语法和合并分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!