无法配置 .gitattributes 对合并有任何影响

Unable to configure the .gitattributes to have any effect for merges

已配置 .gitattributesmerge 驱动程序:

git config --global merge.ours.driver true

$git config -l
push.default=current
pull.default=current
merge.ours.driver=true

这是回购协议 gitattributes 文件中的内容(在 .git/info/attributes 下):

$cat .git/info/attributes

keys_manager/* merge=ours
js/README.md merge=theirs

keys_manager 目录已在第一个分支(我们的)中删除,并在第二个(他们的)分支中对其进行了更改。已对远程端 keys_manager 内的文件和两个分支上的 js/README.md 内的文件进行了更改。

现在让我们对提交做一个干燥的运行:

git merge --no-commit --no-ff origin/audiorec

结果:

CONFLICT (modify/delete): keys_manager/init_db.sql deleted in HEAD and modified in 
origin/audio-recorder. Version origin/audio-recorder of keys_manager/init_db.sql left in tree.

Auto-merging js/README.md
CONFLICT (content): Merge conflict in js/README.md
Automatic merge failed; fix conflicts and then commit the result.

这些不是预期的 .gitattributes 影响结果,而是普通结果,就好像 .gitattributes 不存在一样。为什么没有生效?

如果存在 low-level 冲突,您的合并驱动程序将用于 keys_manager/init_db.sql。但实际上:

CONFLICT (modify/delete): keys_manager/init_db.sql deleted in HEAD
and modified in origin/audio-recorder ... [snip]

您遇到了 high-leveltree 冲突,而不是 low-level 冲突。即一方彻底删除文件,另一方修改文件。标准合并策略总是将修改后的文件作为临时(冲突)结果,并在发生冲突时停止。如果您希望最终结果删除该文件,您可以直接删除该文件。

同时,这:

Auto-merging js/README.md
CONFLICT (content): Merge conflict in js/README.md

一个low-level冲突,所以你的合并驱动程序:

js/README.md merge=theirs

应该已经调用了。您显示:

merge.ours.driver=true

但是 merge.theirs.driver 设置的是什么?如果不设置,则忽略使用自己的驱动程序的说明; Git 使用其 built-in low-level 合并驱动程序。