【问题标题】:.gitattributes merge driver is not used.gitattributes 未使用合并驱动程序
【发布时间】:2014-03-22 12:10:05
【问题描述】:

起初,我知道这个问题How do I tell git to always select my local version for conflicted merges on a specific file?,但这篇文章对我没有帮助,因为我的声誉,我无法添加任何 cmets。

http://git-scm.com/book/en/Customizing-Git-Git-Attributes 建议将合并策略设置为我们的路径,而不是设置自定义合并驱动程序。

添加自定义合并驱动程序返回退出代码 0 有什么好处和区别?

我的仓库顶层有一个 .gitattributes 文件:

pom.xml merge=ours

但是当我将两个分支与已更改的 pom.xml 文件合并时,合并无法解决:

$ git merge origin/master
Auto-merging pom.xml
CONFLICT (content): Merge conflict in pom.xml
Automatic merge failed; fix conflicts and then commit the result.

我得到一个标准的合并冲突结果:

<pom>
<<<<<<< HEAD
    <version>0.88-SNAPSHOT</version>
=======
    <version>0.87.0</version>
>>>>>>> origin/master
</pom>

我做错了什么?

【问题讨论】:

    标签: git merge git-merge gitattributes


    【解决方案1】:

    您可以声明合并驱动程序,但这意味着您必须在 git 配置中定义它,如“.gitattributes & individual merge strategy for a file”:

    [merge "ours"]
        name = "Keep ours merge"
        driver = true
    

    这允许一个文件或一组文件的合并策略,而不是 git merge 的 -s 选项strategies,它不需要您定义驱动程序,但这将解决 所有 文件的冲突(不仅仅是pom.xml)

    git merge -s ours
    

    【讨论】:

    • 问题是我们使用 Atlassian Stash 作为我们的企业 git 存储库,因此我们无法为合并指定任何参数。下一个问题是,我不知道使用合并驱动程序提供拉取请求的任何选项:/ 我正在等待 Atlassian 对此主题的回复。
    • @BlackEye 但如果你定义了一个合并驱动程序,Stash 会选择它,因为它会读取你的 repo 的 .gitattributes。
    • 我不确定,但我认为 Stash 使用临时存储库来合并拉取请求。这样的存储库应该如何知道合并驱动程序?
    • @BlackEye(假设它在您的工作站上进行了合并)它将看到您的 .gitattributes,因为它是您的存储库中的一个文件。但只有在全局选项 (git config --global ...) 中定义驱动程序时它才会知道该驱动程序,因为临时存储库不会看到本地存储库的本地配置。
    • @BlackEye 很容易说服您的 Stash 管理员在 Stash 服务器上的全局配置中声明您的合并驱动程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-02
    • 1970-01-01
    • 2021-10-09
    • 2018-03-02
    • 2018-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多