2

I've created a small script to launch meld when using git diff, similar to this question.

This is fine and all, however due to various drawbacks I'd only like git diff to launch meld in certain circumstances. Is there a way to create an alias in my .gitconfig to allow me to launch meld under certain circumstances?

Thus enters git difftool a way of launching external programs

Community
  • 1
  • 1
AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93

1 Answers1

0

Ends up, yes and no. To do this, you'll want to use git difftool. There are a few gotchas on the way to getting that to work though.

First off, it'll ask you what editor you want to use every time, which is a pain. You'll want to pass a -y flag into difftool.

Assuming the default diff tool git uses, you'll also want to specify exactly what tool you'll want. You can do this two ways, one through -t <toolname> the other --tool=<toolname>.

Assuming you'll always want to default to to be a specific tool, you can set this using the .gitconfig.

[difftool]
    gui = meld

This should set the default tool difftool asks you, let me know if this part isn't accurate.

Here's a final copy of my .gitconfig that has a working alias for difftoool.

[alias]
    mdiff = difftool -t "meld" -y

This has the extra benefit of not having to always wait for meld to open, as well as still being able to get a text diff on the command line.

AlbertEngelB
  • 16,016
  • 15
  • 66
  • 93
  • I don't understand your answer. Could you please try to reformulate the text more clearly and simply? I have exactly the same problem and I am desperately looking for a solution. I would like to launch meld when I am in `X` and `diff` when in console. – Martin Vegter Apr 20 '14 at 14:18
  • @MartinVegter It is very clear and simple. I set up `git difftool` to launch an external diff tool when using the alias `git mdiff `. If you want it to "just work" then copy the alias section into your `.gitconfig` – AlbertEngelB Apr 20 '14 at 17:54