Carina C. Zona bio photo

Carina C. Zona

Email Twitter LinkedIn
git diff
Differences between uncommitted changes vs staged changes.
git diff --cached or git diff --staged
Differences between staged changes vs the latest commit.
git difftool
Use an external application to visualize git diff.
git difftool --tool [name] or git difftool -t [name]
Use a specified external application to visualize git diff.

On OSX, XCode installs one such visual tool, FileMerge, into /Developer/Applications/Utilities/FileMerge.app. You can invoke FileMerge by its commandline name, opendiff. i.e. git difftool -t opendiff. FileMerge/opendiff does a nice job of reporting each change when diffing plain text files, such as uncompiled code.

git help difftool lists other tools it know how to use, such as araxis, bc3, diffuse, emerge, ecmerge, gvimdiff, kdiff3, kompare, meld, opendiff, p4merge, tkdiff, vimdiff and xxdiff. (Not all of these are installed by default. Araxis Merge, for instance, is a commercial product capable of visualizing diffs for Word, Excel, OpenDocument, PDF, RTF, images, and binary files. It's also expensive as heck.)

If your preferred diff tool is not on this list, git config can be used to add custom support for it. git help difftool has details.

For PDFs, I like diffpdf. It's free, open source, and one of the few diff tools that picks up on both visual and textual changes. I own a bunch of beta books, each of which get regular content updates by their authors. It's handy to be able to see exactly what's changing across time in those PDFs, whether it be diagram refinements, clarifying an example, subtle typo fixes, or whole new passages.

How to use git difftool -t diffpdf on OSX

  1. Install homebrew
  2. Install diffpdf
  3. Configure git

By the way, these tools don't necessarily have to be used via git. Generally they allow you to compare any arbitrary two (sometimes even three) files. Note that tools vary as to what, and how, they report changes. diff, for instance, punts on binaries:

$ diff foo.txt bar.txt
1,1
< Hello world
---
> My little pony

$ diff A.jpg B jpg
Binary files A.jpg and B.jpg differ