Git – How to visualize per-character differences in a unified diff file

diff()gitpatchvim

Say I get a patch created with git format-patch. The file is basically a unified diff with some metadata. If I open the file in Vim, I can see which lines have been modified, but I cannot see which characters in the changed lines differ. Does anyone know a way (in Vim, or some other free software that runs on Ubuntu) to visualize per-character differences?

A counter example where per-character diff is visualized is when executing vimdiff a b.

update Fri Nov 12 22:36:23 UTC 2010

diffpatch is helpful for the scenario where you're working with a single file.

update Thu Jun 16 17:56:10 UTC 2016

Check out diff-highlight in git 2.9. This script does exactly what I was originally seeking.

Best Answer

In git, you can merge without committing. Merge your patch first, then do:

git diff --word-diff-regex=.

Note the dot after the equals sign.