18

Has anyone ever made Meld work with Git on Windows? I am trying to make it work and I have no success.

I have Meld installed and when I call it from the command line with two files as parameters it diffs them well so Meld is installed correctly. However I can't make it work with Git (Git Diff). I use version git version 1.8.1.msysgit.1 of Git.

I have tried several things: I created a shell script, meld.sh:

#!/bin/bash
meld.exe "$2" "$5"
echo $2
echo $5

and used it from Git:

[diff]
    tool = meld

[difftool "meld"]
    cmd = \"D:\\meld.sh\"

I tried to add it as a difftool like this:

[diff]
    tool = meld

[difftool "meld"]
    cmd = \"C:\\Program Files (x86)\\Meld\\meld\\meld.exe\" 

or like this:

[diff]
    tool = meld

[difftool "meld"]
    cmd = '\"/c/Program Files (x86)/Meld/meld/meld.exe\" $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE --output=$PWD/$MERGED'

But it really does not seem to work. I also tried to echo the second($2) and fifth($5) parameter from my shell script and no output. I also tried using a batch script in several ways:

meld.exe %2 %5

or

meld.exe %~2 %~5

But it really does not work... How can I pass the two versions of the file Git uses when diffing to Meld? It's pretty annoying...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140

5 Answers5

27

Usually, you can find an example on Windows similar to this gist, with meld.exe being in your PATH):

git config --global merge.tool meld
git config --global mergetool.meld.cmd 'meld.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'

git config --global diff.tool meld
git config --global difftool.meld.cmd 'meld.exe \"$LOCAL\" \"$REMOTE\"'

You can find more robust settings in "Git mergetool with Meld on Windows", but the idea remains the same.


The OP reports in the comments:

For the difftool, your commands write the following configurations in .gitconfig:

[diff]
  tool = meld
[difftool "meld"]
  cmd = meld.exe \\\"$LOCAL\\\" \\\"$REMOTE\\\"

I changed them to:

[diff]
  tool = meld
[difftool "meld"]
  cmd = meld.exe $LOCAL $REMOTE

and everything worked fine.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I tried your method but it does not work properly. Here how it looks like: http://i.imgur.com/KIaVb04.png. If you have any issues in understanding the paths please let me know, I hid the user name and part of the file name. – Jacob Krieg Dec 05 '13 at 15:19
  • Managed to make the `difftool` work. Haven't tried the `mergetool` but chanses are that they will work the same. For the `difftool` your commands write the following configurations in `.gitconfig`: `[diff] tool = meld [difftool "meld"] cmd = meld.exe \\\"$LOCAL\\\" \\\"$REMOTE\\\"` I changed them to: `[diff] tool = meld [difftool "meld"] cmd = meld.exe $LOCAL $REMOTE` and everything worked fine. I will try with `mergetool` later but I will accept your comment :) Thanks! – Jacob Krieg Dec 05 '13 at 15:47
  • 1
    @JasonSwartz great. I have included your comment in the answer for more visibility. – VonC Dec 05 '13 at 16:06
  • I tried meld as a mergetool and i used the same parameters for meld as for the difftool: `cmd = meld.exe $LOCAL $REMOTE` and worked wonderful. Otherwise it crashed probably because of the parameters. Thanks, again! – Jacob Krieg Dec 18 '13 at 09:54
  • removing the quotes on the `$LOCAL` and `$REMOTE` was absolutely key for me. must be like `cmd = meld.exe $LOCAL $REMOTE ` – Jason Joslin Aug 29 '16 at 05:19
  • " [diff] tool = meld [difftool "meld"] cmd = \"D:\\software\\melddiff\\Meld.exe\" $LOCAL $REMOT ". Mine is like this on win7 and I got an error: /usr/libexec/git-core/git-mergetool--lib:行124: D:\software\melddiff\Meld.exe: can't find the command" – Allen Vork Jun 09 '17 at 11:40
  • @AllenVork Strange. Could you ask a separate question, with the exact version of Git and Meld? I suppose you do have the file `D:\software\melddiff\Meld.exe`? – VonC Jun 09 '17 at 15:35
  • I solved it. I change it to "D:/software/melddiff/Meld.exe" and it works.The .gitconfig's format is ubuntu not windows. – Allen Vork Jun 12 '17 at 06:35
7

Or even better, if you're on a locked-down system where fooling with the path is not allowed or you just don't want to pollute your path space, you can just put in the full path to Meld.

I also prefer my current working code copy to show up on the left, so I swapped the $REMOTE and $LOCAL arguments. Also mind the conversions of \ to / and don't for get to escape the double quotes.

[diff]
    tool = meld
[difftool "meld"]
    cmd = \"C:/Program Files (x86)/Meld/meld/meld.exe\" $REMOTE $LOCAL
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mechsin
  • 603
  • 7
  • 11
6

For Windows 7 (or even other versions of windows), add these lines in the .gitconfig file.

[diff]
    tool = meld
[merge]
    tool = meld
[difftool "meld"]
    path = C:/Program Files (x86)/Meld/meld.exe
[mergetool "meld"]
    path = C:/Program Files (x86)/Meld/meld.exe

Note that there is no need to use " for the path even if it includes spaces. Just remember to use forward slashes instead of backward slashes.

Pierre Gramme
  • 1,209
  • 7
  • 23
Rajeev
  • 71
  • 1
  • 3
  • It works in Windows Server 2012 R2 out of the box. Easiest solution found. – pperejon Jan 15 '18 at 10:31
  • Doesn't work on Windows 10 with latest versions of GIt and Meld. – navjotjsingh Jul 25 '19 at 12:39
  • Clean solution for both diff and merge, thanks! Minor comment, based on my experience and on all other answers posted here: the default path to Meld rather seems to be `C:/Program Files (x86)/Meld/meld.exe`. I'll propose an edit in the answer – Pierre Gramme Jun 30 '20 at 09:01
  • For meld version 3.20.3, the default installation path is `C:/Users/UserName/AppData/Local/Programs/Meld/Meld.exe`, so the path should be `path = C:/Users/UserName/AppData/Local/Programs/Meld/Meld.exe` – kohane15 Apr 15 '21 at 02:23
2

I tried several variations of trying to set the path with git config to no avail. Since I want to use Meld from the Git Bash console window, what did work was to export the path to the Meld directory, restart the Bash shell and lo & behold git difftool --tool-help and git mergetool --tool-help now recognize Meld, and I can choose it as my preferred tool.

.profile

export PATH=/c/Program\ Files\ \(x86\)/Meld/:$PATH

.gitconfig

[merge]
    tool = meld
[diff]
    tool = meld
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cathy
  • 67
  • 3
1

Another tip for users invoking diff from gitk (by right-clicking the context menu item "External Diff"):

The above settings may get overridden by gitk's preferences. In that case, change the tools in gitk's menu EditPreferencesGeneralExternal diff setting.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
TingQian LI
  • 660
  • 8
  • 13