Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitattributes not making a difference, trying to skip files when using git difftool

Tags:

git

diff

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!

like image 875
hbCyber Avatar asked Sep 30 '11 08:09

hbCyber


2 Answers

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 the git 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
like image 139
patthoyts Avatar answered Oct 16 '22 22:10

patthoyts


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

lsof | grep "git-difftool--helper"
like image 44
Chris Avatar answered Oct 16 '22 22:10

Chris