colordiff: put some color in your diffs

January 9th, 2008 edited by Patrick Murena

Article submitted by arno. We are running out of articles! Please help DPOTD and submit good articles about software you like!

colordiff is a small tool to colorize diff output which greatly improves readability.

colordiff can be used as a wrapper around diff, a tool used to compare files line by line. Simply run:

$ colordiff file1 file2

That will output differences between file1 and file2 in a colored way. You can also pass diff options to colordiff. So, to output a colored difference between two directories, you can run:

$ colordiff -Nur dir1 dir2

colordiff can also be used through a pipe. Just give it some diff content on its input and it will output the same content with colors.

$ cat some_patch_file | colordiff


$ cvs diff | colordiff

colordiff even works with wdiff since version 1.0.7 (currently only in Debian unstable, not in Ubuntu).

Default colors are very clean on a dark terminal: blue for new text, red for old text, magenta for other diff stuff. You can also modify them easily if you wish. Because colordiff has no way to determine if it writes on a dark or on a light terminal, default colors may be quite harsh on a white terminal. So, colordiff comes with colordiffrc-lightbg file, a configuration example for light backgrounds.

Related tools

Many text editors can display differences with two or more files. Graphical tool xxdiff can display differences between two or three files (it also has more features).

If you like to colorize everything on the console, you may like ccze to colorize log files, colormake to colorize make output, colorgcc to colorize gcc output, or highlight (with --ansi option) to colorize source code for more than 100 languages.


diff alias

Colordiff can be used anywhere diff is used. So, you may want to set colordiff as an alias for diff. Put in your shell configuration file:

alias diff=colordiff
svndiff function

If you use version control regularly, it may be useful to define a diff wrapper in your ~/.bashrc, ~/.zshrc, or other shell configuration file. For example, here is my svndiff function:

svndiff () { svn diff "${@}" | colordiff | less -R -E }

So, I can run svndiff in a directory controlled by svn, and get very readable differences information. You can find a cvsdiff function in colordiff manual, or write one for your favorite control version.


You can find some screenshots on colordiff site:

colordiff is available in Debian from oldstable Sarge to unstable Sid and for Ubuntu from Dapper to Gutsy.

Posted in Debian, Ubuntu |

9 Responses

  1. Jaap Says:

    In bash you’ll need to add a semicolon at the end of the compound statement.
    Also the -E option for less is optional.

    svndiff () { svn diff “${@}” | colordiff | less -R; }

  2. Scott Carlson Says:

    Another way to integrate to subversion is to update the diff-cmd in .subversion/config. This can be a shell script. Mine now looks like:

    /usr/bin/colordiff -wb “$@”

  3. John Carter Says:

    By far the gnicest diff tool on Debian systems these days is “meld”.

    Never leave home without it.

  4. salty-horse Says:

    I prefer using Vim for my diff coloring:
    $ diff a b | vim -

  5. Karl Schmidt Says:

    Ditto on meld - it is ‘the’ tool for diffing and fixing files.

  6. Tom Fernandes Says:

    Instead of
    $ diff a b | vim -
    I use
    $ diff a b | view -
    Like this I don’t have to add the “!” for leaving vi :).

  7. John Says:

    Also don’t forget the colored diff extension for thunderbird… really useful

  8. Jonathan Ballet Says:

    Instead of :
    $ diff a b | vim -

    I prefer to use :
    $ vimdiff a b

    which allows you to copy diff hunks between both files.
    Very nice!

  9. Alikus Says:

    I think you should use Subversion config file for use colordiff as a diff program instead of alias svn diff.

    For example:
    alikus@hostalikus:~$ cat ~/.subversion/config

    diff-cmd = colordiff