Using meld with git diff

One of the things I’ve found myself doing more of is merging in code for other people.  Most of this are changes/additions/deletions to XML files.  And one thing that is really annoying to do is doing these by hand.  Well, fortunately there is a great tool for helping with this.  it’s called Meld.  To get it to play nicely with git we have to do one small thing.  Create a bash script called “git-meld” and put in your bin directory

meld $2 $5

Then make it executable with chmod.  Now add the following to your ~/.gitconfig file

[diff] external = git-meld

This will now run meld whenever you do a git diff.  You can easily see diffs and apply diffs with it now.  If you click the arrow in the blue/green box it will move that chunk of code over.  If you diff multiple files, meld will run with each one of the files, so just quit out of meld and it will relaunch with the next file.

This entry was posted in Computers and tagged , . Bookmark the permalink.
  • bruno

    That works, thanks.

    Be careful with the quotes around $2 and $5, they are wrong.

    meld “$2” “$5” (right)
    meld “$2″ “$5″ (wrong)

  • bruno

    Sorry, wordpress replace the quotes 🙁

    That is right:

    [sourcecode language=”bash”]
    meld “$2” “$5”

  • hannes

    Hey thanks, that helped.
    But I actually had to remove the quotes to make it work. Maybe it changed over time?

  • I too had to remove the quotes. It works fine without them.

  • Leonardo Rochael Almeida

    One can also use the “git difftool” command, which has direct knowledge of many diffing tools, including meld.

    By default it always asks for which diffing tool to use (and defaults to ‘meld’ on my box), but you can automate the choice with configuration variables. See “git help difftool” for details.

  • Brian Dill

    I still find this helpful. Thanks!

  • Thanks! This helped me out. I’d like it if there was such an option.

  • Even easier is just to launch meld in a Git repository. Meld understands Git repositories and will show modified files in a natural way, with diffs. Works for Mercurial and SVN too.

  • Use command

    git config –global diff.external git-meld

    not to bother with editor.

  • Kaitain

    ” If you diff multiple files, meld will run with each one of the files, so just quit out of meld and it will relaunch with the next file.”

    Really? I didn’t see that happening. i.e. I typed

    git diff

    …when there were three files with diffs. With the default command line text diff, I’d see the diffs for all three files from calling that command. With this meld script, it just diffs one file, and that’s it. Nothing else is launched if I quit out of meld.

  • Anonymous

    you can also do
    git config –global diff.external git-meld
    instead editing the config file of git

  • Samuel Mburu

    If ever you want to remove the tool you set, run this command

    git config –global –unset meld


    git config –global –unset meld.external

    I’m not sure if you need to run both commands as I was in a rush when I ran them, but running them both, worked for me.