【问题标题】:Can git apply leave conflict markers inline like git rebase?git 可以像 git rebase 那样应用内联保留冲突标记吗?
【发布时间】:2012-03-31 01:11:57
【问题描述】:

git rebase 将冲突标记保留在文件中;类似:

<<<<<<< HEAD
Whatever line + context is different from the previous commit
=======
Whatever line + context is different from the commit being applied
>>>>>>> new version, new branch:app/views/common/version.txt

当我使用 git apply 应用使用 git format-patch 创建的补丁时,默认情况下它不会留下任何修改过的文件。我可以给它 --reject ,这将导致它为那些有无法解决的冲突的人创建 .rej 文件,但实际上,我希望它修改文件并让每个文件都处于 git rebase 所做的状态,这样我就可以打开文件,手动合并它,然后 git add 它并告诉 git apply 继续。有什么我不知道的方法吗?

【问题讨论】:

    标签: git conflict rebase apply


    【解决方案1】:

    另一种解决方案是使用patch --merge 而不是任何 git 工具来应用补丁。从完全不同的 git repo 带来一些更改时,这对我来说效果更好,因此我不能(轻松)使用 git am -3git apply -3

    【讨论】:

    • 它甚至可以做:patch --merge=diff3
    【解决方案2】:

    使用三路合并选项:

    git apply -3 0001-patch.patch
    

    【讨论】:

    • 这不起作用:错误:补丁失败:file.cpp:383 错误:存储库缺少必要的 blob 以回退到 3 路合并。错误:file.cpp:补丁不适用
    【解决方案3】:

    对我来说,以下作品:

    git init
    seq 1 30 > file
    git add file
    git commit -m 1-30
    sed -i '13a13.4' file
    git commit -m 'add 13.4' file
    git format-patch -1
    git reset --hard HEAD^
    sed -i 13d file
    git commit -m 'remove 13' file
    git am -3 0001-add-13.4.patch
    

    之后file 有冲突标记。那就是使用git am -3 而不是git apply

    【讨论】:

    • Hmmm - 有趣的是,它确实似乎在做我想要的。我认为 git 使用了 git apply - 也许它使用了一个无法通过 git apply 的命令行选项访问的内部 API。谢谢!
    • TL;DR:使用-3 选项到git amgit apply (无论你碰巧使用哪个)。该选项告诉 git 执行合并而不是仅仅在冲突时中止。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    相关资源
    最近更新 更多