Home > Uncategorized > Melding Git

Melding Git

October 29th, 2009 subogero

After switching to Linux, one feels the need to switch to an equally cool version control system as well. And none is cooler than the one invented by Linus Torvalds himself: Git.

It’s called the Fast Version Control System. Being an MKS user professionally, git was a bit on the scary side. No GUI, strange commands and a completely different workflow. Instead of the central repo, there is cloning, pulling and pushing. Instead of the rigid but readable version numbering, there are unreadable SHA1 hashes but, at the same time, user-defined tags as well. Instead of locking, there is branching and merging. Instead of dealing with separate files, there is the universal commit. Main advantage: FAST! And I feel the workflow more and more natural.

I could not get used to one thing, however. The “git diff” command displaying source differences. I’m a huge fan of command lines, but there are limits. So I googled for a visual difference tool. I found meld.

sudo apt-get install meld

Then I looked for a way to integrate git and meld, so when I type git diff, it would open meld, instead of displaying that unreadable mess on the terminal. I found Nathan Hoad’s website.

First step is to tell git it should use meld. While the Bash Guru types

git config --global diff.external meld

the Config Wizard adds a few lines to ~/.gitconfig:

  external = /usr/bin/meld

It does not work, however. Git sends 5 parameters to the diff tool, while meld expects only the 2 filenames to compare. So a little filter is needed. Nathan Hoad proposes a Python script:

import sys
import os
os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))

I know that Python is the language of the day, but in this case I felt it was a bit like Shooting a Sparrow with a Cannon, if you allow me this Hungarism. If one is lazy, one needs a one-liner. And the language of choice is non other than the Bourne Again Shell. The filter is called ~/gitvdiff:

git config --global diff.external ~/gitvdiff

And it contents:

meld $2 $5

Let’s see the results.





On the right side you may notice the entire source file displayed. With syntax highlighting. With a map of the diffs. And with the diffs nicely highlighted.

Categories: Uncategorized Tags: , ,
Comments are closed.