the ultimate text diffing helper

I use Git not only for code, but also for text, my most common use case being co-authorship of scientific papers typeset in LaTeX.

While reviewing other author changes, the usual line-by-line diff is often annoying since:

  1. Paragraph re-formatting gets in the way (hello guys accustomed to compulsory Vim's gq or Emacs' M-q): it does not effect the final rendering, but it still hinders peer-review of changes.

  2. Even in the simplest case of a single word change on a single line, it will take some time for your eyes to spot where, along the line, the actual change is.

Stuff like wdiff does help, but I've never looked at how to integrate it with Git, and I still find it a pain in the eyes due to the fancy ASCII arts used to denote additions and deletions (pain that I usually experience when looking at the output of debdiff). There are nice diffing GUIs or editor-integrated solutions out there, but what I've always dreamed of is a plain old cmdline geekism.

Enter Git's --color-words, that can be passed to both show and diff commands. My favorite related Git aliases are as follows:

        wdiff = diff --color-words
        wshow = show --color-words

Here is a sample fancy output, yet very intuitive and console-based, of git show --color-words (text in red denotes deletions, text in green additions):

sample output of git show --color-words (screenshot)

Maybe not new to you, but it has been life-changing for me.

Thanks for the tip

So I had come to the conclusion that the way to integrate wdiff was to add the following to .git/config

[difftool "wdiff"]
    cmd = /usr/bin/wdiff -l ${LOCAL} ${REMOTE} | less

Then you can use wdiff by calling

git difftool --tool=wdiff ...

But I like --color-words a lot better. Thanks for the tip

Comment by Ken Bloom Mon 18 Jan 2010 04:44:00 PM CET
wdiff options
also, wdiff has the -l, -p, -t, and -[wxyz] options that make it possible to replace the ascii art with actual terminal formatting.
Comment by Ken Bloom Mon 18 Jan 2010 04:51:56 PM CET
comment 2
git help show doesn't mention --color-words, as of 1.6.6?
Comment by roy_hu Mon 18 Jan 2010 06:55:08 PM CET
Never mind
Just tried, git show does support --color-words. Thanks for the tip!
Comment by roy_hu Mon 18 Jan 2010 06:57:07 PM CET
And to html
Comment by hendry [] Mon 18 Jan 2010 07:40:20 PM CET
Diff options

"git help show doesn't mention --color-words, as of 1.6.6?"

True, it doesn't list diff-related options but only says: "The command takes options applicable to the git-diff-tree command to control how the changes the commit introduces are shown." That is, I think all the diff options are available with "git show".

Comment by Oz Mon 18 Jan 2010 07:56:16 PM CET
With the deadline approaching ...
You just made my day. Thank you!
Comment by Lukas Wed 20 Jan 2010 01:02:47 PM CET
Very good! But note that ediff does a pretty good job under Emacs, with paragraphs filled or not.
Comment by Anonymous Wed 03 Feb 2010 11:40:00 PM CET