.gitattributes没有什么区别,试图在使用git difftool时跳过文件 [英] .gitattributes not making a difference, trying to skip files when using git difftool
问题描述
我读过Git Pro网站,并且已经阅读了StackOverflow的多个答案,但遗憾的是我无法让.gitattributes为我工作。
每当我使用 git difftool
时,它都会尝试显示二进制文件(如图像文件(PNG))之间的差异。
我在我的.gitattributes文件中尝试了各种组合,但每当运行我的 git difftool
命令时,它仍然尝试比较二进制文件。
在我的存储库文件夹中,我有:
.git
.gitattributes
[我的项目的文件子目录]
我已经为我的.gitattributes文件尝试了许多过滤器组合。例如:
*。pbxproj二进制文件
* .png二进制文件
blockquote>
或者:
*。pbxproj binary -diff
* .png二进制-diff
偶:
*。pbxproj二进制文件
* .png二进制文件
* .pbxproj -diff -difftool
* .png -diff -difftool
每一次,我只需将我的.gitattributes文件添加到索引并提交它。但是,这样做后,当我运行我的
git difftool
来检查两个分支之间的差异时,会发生这种情况:
git difftool otherBranch HEAD
查看:'MyApp.xcodeproj / project.pbxproj '
点击返回以启动'diffmerge':
查看:'MyApp / Background1.png'
点击返回以启动'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 apears永远不会查看属性。我相信这是因为difftool基本上调用与mergetool相同的代码,并且支持二进制文件的合并(如果仅通过复制一个)。附加的修补程序是对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
}
+如果测试$(git check-attr diff$ 1| sed's /.* diff://' )='unset';那么
+ echo跳过二进制文件\$ 1 \
+ else
+
if! use_ext_cmd;那么
如果测试-n$ GIT_DIFF_TOOL;然后
merge_tool =$ GIT_DIFF_TOOL
@@ -70,3 +74,4 @@
launch_merge_tool$ 1$ 2$ 5
转换7
完成
+ fi
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.
Whenever I'm using
git difftool
, it will attempt to display the difference between binary files, such as image files (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.In my repository's folder, I have:
.git
.gitattributes
[my project's files subdirectories]I have tried many combinations of filters for my .gitattributes file. For example:
*.pbxproj binary
*.png binaryOr also:
*.pbxproj binary -diff
*.png binary -diffEven:
*.pbxproj binary
*.png binary
*.pbxproj -diff -difftool
*.png -diff -difftoolEvery time, I simply add my .gitattributes file to the index and commit it. However, after doing so, when I run my
git difftool
to examine my differences between two branches, this happens:
git difftool otherBranch HEAD
Viewing: 'MyApp.xcodeproj/project.pbxproj' Hit return to launch 'diffmerge':
Viewing: 'MyApp/Background1.png' Hit return to launch '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?
To further investigate, I have used the
git check-attr
command as follows:
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!解决方案It looks like this is a deficiency in 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 thegit diff
output for any .proj files to 'binary files differ'. However, difftool apears never to look at the attributes. 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). 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. It is probably something for the git mailing list.--- 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
这篇关于.gitattributes没有什么区别,试图在使用git difftool时跳过文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!