Last Updated: February 25, 2016
·
1.846K
· arichiardi

Better binary diffs in Git

Git can handle custom binary diffs as text and therefore display meaningful diff messages if properly configured.

Just add the following to your .gitconfig:

[diff "png"]
    binary = true
    textconv = hexdump -v -C
[diff "jpg"]
    binary = true
    textconv = hexdump -v -C
[diff "jpeg"]
    binary = true
    textconv = hexdump -v -C

There <b>has to</b> be a diff+textconv definition for each extension you want to handle.

For more complicated diffs you might want to set a third-party tool like ImageMagick for images or pdfinfo for pdf files:

[diff "pdf"]
   binary = true
   textconv = pdfinfo

The binary boolean is useful when <i>"... you want to use textconv to convert files to an ASCII representation for human viewing, but otherwise treat them as binary files."</i>

For a depeer understanding of this part of git customization, check this link on the so called <b> gitattributes</b>.