<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>Are you using [Git](http://git.or.cz/) in Ubuntu and want to use an external visual diff viewer? It's easy! I will be using [Meld](http://meld.sourceforge.net/) for this example but most visual diff tools should be similar. If you don't already have Meld, then install it:

&lt;code class="terminal"&gt;sudo apt-get install meld&lt;/code&gt;

Ok. Now let's begin by breaking it. Enter this into a terminal:

&lt;code class="terminal"&gt;git config --global diff.external meld&lt;/code&gt;

Then navigate to a Git tracked directory and enter this (with an actual filename):

&lt;code class="terminal"&gt;git diff filename&lt;/code&gt;

Meld will open but it will complain about bad parameters. The problem is that Git sends its external diff viewer seven parameters when Meld only needs two of them; two filenames of files to compare. One way to fix it is to write a script to format the parameters before sending them to Meld. Let's do that.

Create a new python script in your home directory (or wherever, it doesn't matter) and call it _diff.py_.

    #!/usr/bin/python
    
    import sys
    import os
    
    os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))

Now we can set Git to perform it's diff on our new script (replacing the path with yours):

&lt;code class="terminal"&gt;git config --global diff.external /home/nathan/diff.py  
git diff filename&lt;/code&gt;

This time when we do a diff it will launch Meld with the right parameters and we will see our visual diff.</body>
  <created-at type="datetime">2009-06-03T23:07:29+10:00</created-at>
  <id type="integer">38</id>
  <project-id type="integer" nil="true"></project-id>
  <published type="boolean">true</published>
  <published-at type="datetime">2008-06-02T22:10:00+10:00</published-at>
  <title>How To: Meld for Git Diffs in Ubuntu Hardy</title>
  <updated-at type="datetime">2009-06-03T23:08:24+10:00</updated-at>
  <url>how-to-meld-for-git-diffs-in-ubuntu-hardy</url>
</post>
