Cherry-pick和patch的区别是什么? [英] What are the difference between Cherry-pick and patch apply?
问题描述
我知道git cherry-pick和git apply terminalogies。但今天我遇到了一些问题。我通过使用两个版本的差异来应用一个补丁。我使用了下面的命令:
git diff HEAD> diff.patch
git apply diff.patch
我得到的补丁申请失败的一个文件。
<然后,我只是尝试 cherry-pick commit-id2。它被成功挑选出来。
可能是什么原因?任何人都想抛出一些同样的东西。
两种可能性: 您没有告诉 请尝试以下操作: 上面的行为应该像 I am aware about git cherry-pick and git apply terminalogies. But today i came across with some issue. I was applying one patch by using the diff of two revisions. I used the below command: git diff HEAD > diff.patch git apply diff.patch I got patch apply failed for one file. Then i simply tried to cherry-pick the commit-id2. It is cherry-picked successfully. What may be the reason? Anyone wants to throw some light on the same. Two possibilities: The changes in You did not tell Try the following: The above should behave like 这篇关于Cherry-pick和patch的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
diff.patch
中的更改可能与 commit-id2中的更改有所不同。 code $> git diff HEAD
显示了 git cherry-pick commit-id2
应用 commit-id2
和它的父级之间的差异(并使用元数据来自 commit-id2
)。 commit-id2
及其父项之间的差异不是(通常)与 HEAD
之间的差异工作目录。
git apply
回退到3-way合并 cherry-pick
确实如此。尝试将 - 3way
(或 -3
)选项添加到 git apply
。
git diff commit-id2 ^! > diff.patch
git apply -3 diff.patch
git cherry-pick -n commit-id2
。 (请参阅 git help revisions
对 ^!
语法的解释。)
diff.patch
are probably different from the changes in commit-id2
, which is why the two behaved differently.git diff HEAD
shows the diff between HEAD
and the current working directory. git cherry-pick commit-id2
applies the diff between commit-id2
and its parent (and commits the result using the metadata from commit-id2
). The diff between commit-id2
and its parent is not (usually) the same as the diff between HEAD
and the current working directory.git apply
to fall back to a 3-way merge like cherry-pick
does. Try adding the --3way
(or -3
) option to git apply
.git diff commit-id2^! >diff.patch
git apply -3 diff.patch
git cherry-pick -n commit-id2
. (See git help revisions
for an explanation of the ^!
syntax.)