.gitattributes 没有什么区别,在使用 git difftool 时尝试跳过文件
我已经阅读了 Git Pro 网站,并且在 StackOverflow 上阅读了多个答案,但遗憾的是我根本无法让 .gitattributes 为我工作。
每当我使用 git difftool 时,它都会尝试显示二进制文件之间的差异,例如图像文件 (PNG)。
我在 .gitattributes 文件中尝试了各种组合,但每当我运行 git difftool 命令时,它仍然尝试比较二进制文件。
在我的存储库文件夹中,我有:
.git
.gitattributes
[我的项目的文件子目录]
我已经为我的 .gitattributes 文件尝试了多种过滤器组合。例如:
*.pbxproj 二进制文件
*.png 二进制
或者也可以:
*.pbxproj 二进制 -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 仍然强迫我查看差异!
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 binary
Or also:
*.pbxproj binary -diff
*.png binary -diff
Even:
*.pbxproj binary
*.png binary
*.pbxproj -diff -difftool
*.png -diff -difftool
Every 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来这是 difftool 的一个缺陷。如果您按照描述使用 .gitattributes 文件,则“git diff”的输出将按预期修改,因此设置
*.proj binary
或*.proj -diff
会发生变化任何 .proj 文件的 git diff 输出为“二进制文件不同”。然而,difftool 似乎从不查看属性。我相信这是因为 difftool 基本上调用与 mergetool 相同的代码,并且支持二进制文件的合并(如果仅通过复制一个文件到另一个文件)。附加的补丁是对 difftool-helper 脚本的一个小更改,这应该会导致它跳过设置了二进制属性的文件。这可能是 git 邮件列表的内容。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.patthoyts 的答案为我工作。
对我来说,诀窍是找出我使用的 git-difftool--helper 版本(MacPorts 已经安装了多个版本)
(在打开 difftool 的情况下):
patthoyts's answer worked for me.
The trick for me was figuring out version of
git-difftool--helper
git was using (MacPorts had installed multiple versions)I used (with the
difftool
open):