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

#!/bin/bash
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. Bookmark the permalink.

9 Responses to Using meld with git diff

  1. bruno says:

    That works, thanks.

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

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

  2. bruno says:

    Sorry, wordpress replace the quotes :(

    That is right:

    [sourcecode language="bash"]
    #!/bin/bash
    meld “$2″ “$5″
    [/sourcecode]

  3. hannes says:

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

  4. Alex Ford says:

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

  5. Leonardo Rochael Almeida says:

    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.

  6. Brian Dill says:

    I still find this helpful. Thanks!

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

  8. Drew Noakes says:

    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.

  9. zekefast says:

    Use command

    git config –global diff.external git-meld

    not to bother with editor.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>