[英].gitattributes not making a difference, trying to skip files when using git difftool
I've read the Git Pro website and I've read multiple answers on StackOverflow, but sadly I am simply unable to make .gitattributes work for me. 我已经阅读了Git Pro网站,并且我已经在StackOverflow上阅读了多个答案,但遗憾的是我无法让.gitattributes为我工作。
Whenever I'm using git difftool
, it will attempt to display the difference between binary files, such as image files (PNG). 每当我使用
git difftool
,它都会尝试显示二进制文件之间的差异,例如图像文件(PNG)。
I have tried a variety of combinations in my .gitattributes file, but whenever I run my git difftool
command, it still attempt to compare the binary files. 我在.gitattributes文件中尝试了各种组合,但每当我运行我的
git difftool
命令时,它仍然会尝试比较二进制文件。
In my repository's folder, I have: 在我的存储库文件夹中,我有:
.git git的
.gitattributes .gitattributes
[my project's files subdirectories] [我的项目的文件子目录]
I have tried many combinations of filters for my .gitattributes file. 我为.gitattributes文件尝试了很多过滤器组合。 For example:
例如:
*.pbxproj binary
* .pbxproj二进制文件
*.png binary* .png二进制文件
Or also: 或者:
*.pbxproj binary -diff
* .pbxproj binary -diff
*.png binary -diff* .png二进制文件-diff
Even: 甚至:
*.pbxproj binary
* .pbxproj二进制文件
*.png binary* .png二进制文件
*.pbxproj -diff -difftool* .pbxproj -diff -difftool
*.png -diff -difftool* .png -diff -difftool
Every time, I simply add my .gitattributes file to the index and commit it. 每次,我只需将我的.gitattributes文件添加到索引并提交它。 However, after doing so, when I run my
git difftool
to examine my differences between two branches, this happens: 但是,在这样做之后,当我运行我的
git difftool
来检查两个分支之间的差异时,会发生这种情况:
git difftool otherBranch HEAD
Viewing: 'MyApp.xcodeproj/project.pbxproj' Hit return to launch 'diffmerge':
查看:'MyApp.xcodeproj / project.pbxproj'点击返回启动'diffmerge':
Viewing: 'MyApp/Background1.png' Hit return to launch 'diffmerge':
查看:'MyApp / Background1.png'点击返回启动'diffmerge':
How come it's doing this? 它是怎么做到的? How can I finally set my .gitattributes file properly so I do not have to view the diffs for these specific files?
我怎么能最终正确设置我的.gitattributes文件,所以我不必查看这些特定文件的差异?
To further investigate, I have used the git check-attr
command as follows: 为了进一步研究,我使用了
git check-attr
命令,如下所示:
git check-attr binary MyApp/MainBackground.png
The output is MyApp/MainBackground.png: binary: set
... I wonder why git difftool still forces me to view the diff! 输出是
MyApp/MainBackground.png: binary: set
...我想知道为什么git difftool仍然迫使我查看差异!
It looks like this is a deficiency in difftool. 看起来这是difftool的缺陷。 If you use the .gitattributes file as you have described then the output of 'git diff' is modified as intended so setting
*.proj binary
or *.proj -diff
changes the git diff
output for any .proj files to 'binary files differ'. 如果你正如你所描述的那样使用.gitattributes文件,则'git diff'的输出会按预期修改,因此设置
*.proj binary
或*.proj -diff
会将任何.proj文件的git diff
输出更改为'二进制文件不同”。 However, difftool apears never to look at the attributes. 然而,difftool apears永远不会查看属性。 I believe this is because difftool basically calls the same code as mergetool and merging of binary files is supported (if only by copying one over the other).
我相信这是因为difftool基本上调用与mergetool相同的代码,并且支持合并二进制文件(如果仅通过复制一个而不是另一个)。 The attached patch is a small change to the difftool-helper script that should cause it to skip files for which the binary attribute is set.
附加的补丁是对difftool-helper脚本的一个小改动,它应该使它跳过设置了二进制属性的文件。 It is probably something for the git mailing list.
它可能是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
patthoyts 's answer worked for me. patthoyts的回答对我有用 。
The trick for me was figuring out version of git-difftool--helper
git was using (MacPorts had installed multiple versions) 我的诀窍是找出
git-difftool--helper
版本git-difftool--helper
git正在使用(MacPorts已经安装了多个版本)
I used (with the difftool
open): 我用过(用
difftool
打开):
lsof | grep "git-difftool--helper"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.