Subversion diff with vimdiff

| 3 Comments | Bookmark and Share

Side by side diffs are much more legible and useful than those in unified format or any other linear diff. By default, the svn diff command presents output in the unified format, though it has an option, --diff-cmd, which allows you to specify the program that will perform the diff. Passing vimdiff as the diff command doesn't work as the options passed by svn diff are a bit complicated:

~/code/perllib/MG$ cat foo.sh
\#!/bin/bash
echo $*
~/code/perllib/MG$ svn diff --diff-cmd foo.sh Proxy.pm
Index: Proxy.pm
-u -L Proxy.pm (revision 21095) -L Proxy.pm (working copy) .svn/text-base/Proxy.pm.svn-base /tmp/svndiff.tmp

Subversion is telling diff to output context (-u), show pretty names for the files (-L) and then the two files to diff. To make this work with vim, we simply need to cut out the extra options. To do so, I wrote a simple script:

\#!/bin/bash
shift 5
vimdiff "$@"

I put that in ~/bin/svnvimdiff and now I can do svn diff --diff-cmd ~/bin/svnvimdiff Proxy.pm and view the diff in vimdiff. Since this is a command I use often, I aliased it in my .bashrc:

alias svndiffvim='svn diff --diff-cmd ~/bin/svnvimdiff'

3 Comments

Works great, thanks for this tip!

you could also put that script name in ~/.subversion/config to the diff-cmd variable. then just svn diff file.txt, or svn diff -r 10:11 file.txt

Thank you, it worked for me. I did not know why I couldn't use vimdiff as a --diff-cmd and searched around and your page came up. Thanks.

Leave a comment

About this Entry

This page contains a single entry by Drew Stephens published on June 12, 2008 11:03 AM.

Keeping Your Home Directory in Subversion was the previous entry in this blog.

Apache Won't Start: No space left on device is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 5.1