gpt4 book ai didi

git - .gitattributes 没有区别,在使用 git difftool 时尝试跳过文件

转载 作者:太空狗 更新时间:2023-10-29 12:47:04 25 4
gpt4 key购买 nike

我已经阅读了 Git Pro 网站并阅读了 StackOverflow 上的多个答案,但遗憾的是我无法让 .gitattributes 为我工作。

每当我使用 git difftool 时,它都会尝试显示二进制文件(例如图像文件 (PNG))之间的差异。

我在我的 .gitattributes 文件中尝试了多种组合,但每当我运行我的 git difftool 命令时,它仍然会尝试比较二进制文件。

在我存储库的文件夹中,我有:
.git
.git 属性
[我项目的文件子目录]

我为我的 .gitattributes 文件尝试了多种过滤器组合。例如:

*.pbxproj binary
*.png binary

或者还有:

*.pbxproj binary -diff
*.png binary -diff

甚至:

*.pbxproj binary
*.png binary
*.pbxproj -diff -difftool
*.png -diff -difftool

每次,我只需将我的 .gitattributes 文件添加到索引并提交即可。但是,这样做之后,当我运行 git difftool 来检查两个分支之间的差异时,会发生这种情况:

git difftool otherBranch HEAD

Viewing: 'MyApp.xcodeproj/project.pbxproj' Hit return to launch 'diffmerge':

Viewing: 'MyApp/Background1.png' Hit return to launch 'diffmerge':

为什么会这样?我怎样才能最终正确设置我的 .gitattributes 文件,这样我就不必查看这些特定文件的差异?

为了进一步调查,我使用了 git check-attr 命令如下:
git check-attr binary MyApp/MainBackground.png

输出是 MyApp/MainBackground.png: binary: set ...我想知道为什么 git difftool 仍然强制我查看差异!

最佳答案

看起来这是 difftool 的一个缺陷。如果您按照描述使用 .gitattributes 文件,则“git diff”的输出会按预期进行修改,因此设置 *.proj binary*.proj -diff 会发生变化任何 .proj 文件的 git diff 输出到“二进制文件不同”。但是,difftool 似乎永远不会查看属性。我相信这是因为 difftool 基本上调用与 mergetool 相同的代码,并且支持 merge 二进制文件(如果只是通过将一个复制到另一个)。附加的补丁是对 difftool-helper 脚本的一个小改动,应该会导致它跳过设置了二进制属性的文件。它可能是 git 邮件列表的东西。

--- git-difftool--helper    2011-06-03 21:48:08.000000000 +0100
+++ /opt/git/libexec/git-core/git-difftool--helper 2011-10-06 13:17:55.000000000 +0100
@@ -56,6 +56,10 @@
fi
}

+if test $(git check-attr diff "$1" | sed 's/.*diff: //') = 'unset'; then
+ echo skip binary file "\"$1\""
+else
+
if ! use_ext_cmd; then
if test -n "$GIT_DIFF_TOOL"; then
merge_tool="$GIT_DIFF_TOOL"
@@ -70,3 +74,4 @@
launch_merge_tool "$1" "$2" "$5"
shift 7
done
+fi

关于git - .gitattributes 没有区别,在使用 git difftool 时尝试跳过文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7607739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com