How can I diff binary files in git?

In order to diff binary files in git, I assume I need to set up a difftool.

What difftools work? How do you put the parameters in?


Solution 1:

If you want to force git to show binary files diff as a plain text diff use --text option like so:

git diff --text

Solution 2:

You can set a textconv config option for a filetype. See "Performing text diffs of binary files" in gitattributes(5). What you should use depends on the filetype.

Example 1:

Say you want to diff the contents of zip files. In that case you should put in one of the following files $XDG_CONFIG_HOME/git/config or $HOME/.gitconfig or $GIT_DIR/config .

[diff "zip"]
    textconv = unzip -v

Next time you ask for a diff on a zip file in a repo, it will call unzip -v on both version and diff the resulting text.

Example 2:

For pdf files you could use e.g. pdfinfo;

[diff "pdf"]
    textconv = pdfinfo

Example 3:

If there is no specific infomation utility for a filetype, you could e.g. use hexdump (comes with FreeBSD and OSX, also available on Linux):

[diff "bin"]
    textconv = hexdump -v -C