Pretty (colorized) CVS/SVN diff from CLI

Last modified: November 10, 2007 - 21:00

If you've ever read a colorized diff (ie, + lines are one color, - lines another...) you've probably found them much easier to navigate. Programs like vimdiff and Textmate can show diffs with this kind of output. But what about us poor folks running 'cvs diff -up' against a repository?

After much hunting, I've finally found a program that makes colorized diffs possible in this case:

http://colordiff.sourceforge.net/

If you run a package manager, there's a good chance it's available there (I installed it right from Fink).

Once installed, put the two functions below into your bash profile (it's in your home directory, called .bashrc, or .bash_profile, or maybe .profile) -- make sure to start a new shell or source the profile so the changes will take effect. Now you've got a completely integrated way to get much nicer output! I've also included a helper for SVN:

# color diffs for CVS
function cvsdiff () {
  if [ "$1" != "" ]; then
    cvs diff $@ | colordiff;
  else
    cvs diff | colordiff;
  fi
}

# color diffs for SVN
function svndiff () {
  if [ "$1" != "" ]; then
    svn diff $@ | colordiff;
  else
    svn diff | colordiff;
  fi
}

Once both the colordiff program and the helper functions are installed, you can do cvsdiff -up, or cvsdiff -up foo.patch to get colorized output -- note the difference between this and the regular way is the missing space in the helper function, cvsdiff -up versus cvs diff -up.

Of course you can name the helpers anything you like -- I found those names work for me.

One other note: if you use a terminal with a light background (ie. white), you'll probably want to install the custom color layout for that (colordiff expects your terminal to use a dark background by default). Simply copy the colordiffrc-lightbg file to your home directory, and name it .colordiffrc -- you can find that file from the source code link above, or it might possibly be in your /etc directory if you installed from a package manager.

 
 

Drupal is a registered trademark of Dries Buytaert.