Git Difftool

By Greg Rowe | April 1, 2017

The ability to perform side-by-side comparisons of source code is an absolutely integral tool in software development. While many developers may have developed the skill to happily read diff output directly I have not. I prefer a graphical tool that lets me see a full context and to choose text blocks to include or exclude. It’s very easy to setup this up using git.

The more I work with git the more I love it. I wanted an easier way to view differences. I was pleased to find that this is easy to configure with git and works reasonably well. Git provides a command called difftool which will launch and external diff viewer. With very little effort it becomes painless to graphically view differences.

Setup is incredibly simple. Simply add a section to your ~.gitconfig to tell git which tool you would like to launch when you run git difftool.

By default git difftool will open each file separately. This can be incredibly irritating. As of version 1.7.11 there is an option, --dir-diff, which will perform a directory diff. If your tool supports it you’ll have a very convenient way to view differences without being forced to review each file.

[diff] 
	tool = meld 

To make my life even easier I created an alias. Anytime I want to view a diff I run git d.

[alias]
	d = difftool -y --dir-diff

Meld Screenshot Format: Alt Text

comments powered by Disqus