Subversion diff with vim
<1 min read
Once in a while I have to use Subversion on a Linux box. Not a big deal, except for diffs. The standard svn diff
output is not the most readable. Vim, or more exactly vimdiff, does a terrific job at displaying differences between files side-by-side. Here's a little Bourne shell script I wrote that uses vimdiff to view the differences between a local file and the latest revision in the repository:
Nothing too fancy. It uses svn cat
to get the latest rev, saves it to a temporary file, and opens both files in vimdiff:
The temp file is deleted as soon as vimdiff is quit.
[@389]
I also just found svncommand.vim, a nifty Subversion integration plugin.
Comments
12 (Closed)
christopher baus
Feb 14, 2006
will do it.
Erik C. Thauvin
Feb 14, 2006
E.
Marius Scurtescu
Feb 15, 2006
Give it a try, it does understand Subversion and all you have to do is:
$ meld <your_file>
It can also show diffs for a whole folder structure, just use a folder name instead of a file name.
Fernando Brucher
Apr 3, 2006
That way syntax highlighting works also for the temporary file. I modified the temp file name generation in your script like so:
TEMP=/tmp/tmp.$$.$1
Thanks for creating you script. It works great. And I'm happy to be able to use vimdiff, which I'm familiar with.
Erik C. Thauvin
Apr 3, 2006
Francesc
May 11, 2006
I've found it has problems using directories (ie, 'svndiff lib/foo.php') but it works if you change temp file name with this:
TEMP=/tmp/tmp.$$.`basename $1`
Erik C. Thauvin
May 11, 2006
fREW Schmidt
Nov 25, 2006
I don't know if you actually do any editing when you use this script.
I personally don't so I found it useful to do the following:
vimdiff -R $TEMP $1
Only because I tend to leave files open in vim in between commits and I got sick of the error message and whatnot.
wulf
Mar 25, 2007
You will find my version here
gpl.coulmann.de…
Balbir Singh
Apr 6, 2007
e.g.
trap 'rm -f $tempfile' 0 1 2 15
Thanks for the idea.
Carlo
Jan 16, 2011
It also gives friendly names to the Vim buffers -- Subversion passes these as additional parameters.
Furthermore, it ensures Vim syntax highlighting does not break, in the vein of Francesc's suggestion.
Erik C. Thauvin
Jan 18, 2011
BTW, I just checked in a new version of the script incorporating all of the suggestions posted here.
Thanks,
E.