Git with Meld diff viewer on Ubuntu

June 4, 2011 at 4:58 pm
filed under Debian, Git, Linux, Ubuntu
Tagged , , , ,

Using command line Git with standard diff is workable but not very friendly. You might prefer a split-pane diff viewer like that of your favourite IDE. The easiest way to get this working on Debian based Linux distros such as Ubuntu is to use Meld, the open source diff and merge tool.

Begin by installing Meld:

sudo apt-get update && sudo apt-get install meld

Once installed, open your favourite text editor and create a file called git-diff.sh, using the following content:

#!/bin/bash
meld "$2" "$5" > /dev/null 2>&1

Save this to a location such as /usr/local/bin, giving it executable rights:

sudo mv git-diff.sh /usr/local/bin/
sudo chmod +x /usr/local/bin/git-diff.sh

The final step is to open your $HOME/.gitconfig file and add the following few lines:

[diff]
        external = /usr/local/bin/git-diff.sh

The next time you type git diff in a Git project with changes, Meld will be launched showing you a split-pane diff viewer. Not that you are required to close the open instance of meld before the next diff viewer is opened.

Fork me on GitHub

2 comments

RSS / trackback

respond

 
  1. Colin Harrington

    on June 20, 2011 at 8:49 pm

    This method opens meld for each changed file.

    Meld has some lightweight git support. I like to execute ‘meld .’ while in my repo to see the changes all within one window.

  2. Joe Cabezas

    on July 11, 2011 at 3:08 am

    also, u can repace the final step with this command line:

    git config –global diff.external /usr/local/bin/git-diff.sh

    it will do the replacement for you

    bye!