Cherry-pick和patch的区别是什么? [英] What are the difference between Cherry-pick and patch apply?

查看:519
本文介绍了Cherry-pick和patch的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道git cherry-pick和git apply terminalogies。但今天我遇到了一些问题。我通过使用两个版本的差异来应用一个补丁。我使用了下面的命令:


git diff HEAD> diff.patch



git apply diff.patch


我得到的补丁申请失败的一个文件。



<然后,我只是尝试 cherry-pick commit-id2。它被成功挑选出来。



可能是什么原因?任何人都想抛出一些同样的东西。

解决方案

两种可能性:

diff.patch 中的更改可能与 commit-id2中的更改有所不同。 code $> git diff HEAD 显示了之间的差异, code> 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 ^!语法的解释。)


    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 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.

    • You did not tell git apply to fall back to a 3-way merge like cherry-pick does. Try adding the --3way (or -3) option to git apply.

    Try the following:

    git diff commit-id2^! >diff.patch
    git apply -3 diff.patch
    

    The above should behave like git cherry-pick -n commit-id2. (See git help revisions for an explanation of the ^! syntax.)

    这篇关于Cherry-pick和patch的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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