Diff tools for the command line

The diff tool is like one of the most needed tool in the developer toolbox, however the basic diff works well and does the job but sometimes it has the lack of a good presentation of the changes, you need to be an expert to do a quick read of a diff file and know what is happening, fast. Sometimes for new developers (or when is late and you are tired -_-) a better presentation of the differences will help.

Here is when the GUI help us to do this job better, tools like Meld will do our life less complicated. The most important feature that I see in meld is the possibility to do side by side comparison, that clarifies a lot what have happened with the changeset.

However, sometimes you are in the command line and you need to do a quick diff to verify something small, diff will work, however you are just an human and you want to have side by side comparison and colors, because looks nice, here is when we need something powerful.

Here I have a list of tools that we found with our mates discussing via Slack in the company.

Pipe to vim

An easy way to have nice colors in your diff is just piping the diff output to vim, you’ll always have the diff command and vim, so I guess 60% of the time it works every time.

diff file1 file2 | vim -R -

Icdiff

Is a command line tool to Show differences between files in a two column view, and with colors.

To use it you just need to do

icdiff file1 file2

The output will be something like this

colordiff

Color diff add some basic colors to a simple diff, if is a new line use green if is a deleted line use red. It has no side by side comparison.

You can pipe colordiff to any command that will output a diff file to add some nice colors.

vimdiff

Last but not lest, vimdiff is a tool that using vim will do a side by side comparison and will use nice colors and symbols to explain what is going on with the differences.

As an extra feature, you can edit the files and save the changes.

Integrating icdiff with git for better git diff

If you are using git diff all the time and you are not comfortable with the standard output, you can configure your git client to use icdiff to show the git differences. Just go to your ~/.gitconfig file and add these lines

[diff]
 tool = icdiff
[difftool]
 prompt = false
[difftool "icdiff"]
 cmd = /usr/local/bin/icdiff --line-numbers $LOCAL $REMOTE

To use it, just run in your working copy

$git icdiff

You’ll see the output in a side by side style.

Which one shall I use ?

Use the three, you might need it in different cases depending of what you are doing.

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.