Lars Tesmer's Blog

From Journeyman to Master - A Software Craftsman's Blog

Git - How to Get Better Diffs for Images

Have you ever wondered if there's something that would make Git to show better diffs for images?
Well, here's a really useful addition to one's Git config that will tell Git to use exiftool to create diffs of changes made to images:
cd /path_to_project
echo '*.png diff=exif' >> .gitattributes
echo '*.jpg diff=exif' >> .gitattributes
echo '*.gif diff=exif' >> .gitattributes
git config diff.exif.textconv exiftool
From now on, diffs for images will look something like this:
--- a/img.png
+++ b/img.png
@@ -1,7 +1,7 @@
 ExifTool Version Number         : 7.89
-File Size                       : 8.9 kB
+File Size                       : 8.3 kB
 File Modification Date/Time     : 2010:09:20 16:55:41+02:00
 File Type                       : PNG
 MIME Type                       : image/png
-Image Width                     : 58
-Image Height                    : 80
+Image Width                     : 60
+Image Height                    : 87
Nothing spectacular but much more useful than the default.
Originally, I found this in some slides I read many moons ago. I tried to find those slides again, unsuccessfully.
Luckily, I've found another source explaining how to do it:
Chapter 7 of "Pro Git"
Thanks, Scott Chacon!