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!
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):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.