96

In Linux, my favorite merge tool is Meld, and I've had no problems using or configuring it to work with Git. However, in Windows it has been a different story.

First, I installed Meld from a bundle I found here: https://code.google.com/p/meld-installer/

Then, I configured my .gitconfig like so to support Meld as the default mergetool

[merge]                                                      
    tool = meld                                                                         

[mergetool "meld"]                                           
    path = C:\\Program Files (x86)\\Meld\\meld\\meld.exe
    keepBackup = false                                   
    trustExitCode = false

So, when I have a conflict, I do git difftool and Meld does in fact open. However, the paths to the files that Git writes to pass to the diff tool is incorrect. For example, even though Git generates the BASE, LOCAL, and REMOTE files in the repository directory (the location I called git mergetool from), Meld tries to open each of those files in the directory of the executable.

Instead of opening C:\repo\roses.txt.LOCAL.2760.txt, Meld tries to open C:\Program Files (x86)\Meld\meld\roses.txt.LOCAL.2760.txt.

Has anyone ran into this before or know how to configure Git / Meld to work correctly in Windows?

Nelson
  • 1,607
  • 2
  • 16
  • 24
  • I have no idea if this has any point in being tried, but I use KDiff3, and the path set up in my gitconfig is: path = C:/Program Files (x86)/KDiff3/kdiff3.exe and not C:\\ etc. – Fumler Feb 11 '13 at 22:59
  • 1
    Could you solve the problem? – Roger Jun 11 '13 at 14:11
  • 1
    I have not been able to. One of the answers is probably correct, but I'm hesitant to mark any as such since I can't actually get Meld to behave properly :-/ – Nelson Jun 12 '13 at 01:25
  • @Nelson Don't worry, neither can I :( – abergmeier Sep 23 '13 at 08:33
  • Please comment and vote to [upstream issue](https://gitlab.gnome.org/GNOME/meld/issues/143) so future user won’t even need to worry about this. – Franklin Yu May 01 '19 at 15:56

9 Answers9

155

Why do you not use git bash for Windows?

After install meld simply:

git config --global merge.tool meld
git config --global mergetool.meld.path "C:\Program Files (x86)\Meld\Meld.exe" <- path to meld here

Thats all!

Lyndon White
  • 24,284
  • 15
  • 77
  • 126
Arugin
  • 1,845
  • 1
  • 11
  • 17
  • 1
    This solution worked for me I also did below command to not prompt me every time it opens the tool git config --global mergetool.prompt false – Vineel Oct 10 '15 at 11:29
  • git config --global mergetool.meld.path "C:\Program Files (x86)\Meld\Meld.exe" – Hernán Eche Dec 28 '15 at 12:22
  • 1
    This solution worked for me with Meld 3.16.2, also added git config --global mergetool.keepBackup false to remove those pesky backups. – Jay Sep 11 '16 at 18:23
  • 2
    for some reason, after applying this solution everything appeared as red (changed), and I had to do this: `git config --global mergetool.meld.cmd '"C:\Program Files (x86)\Meld\Meld.exe" $BASE $LOCAL $REMOTE -o $MERGED'` – ihadanny Nov 14 '16 at 08:17
  • How do you run it? when I run it, git says the merge tool failed.... Meld.exe continues running in the background with no window at all, eating CPU, and just creates and leaves a bunch of backup files laying around in the directory. Seems broke as hell. And why wouldn't the installer take care of this? This isn't exactly a command that someone is ever going to guess to enter after running an installer and watching something completely broken fail to work at all. Ridiculous. – Triynko Feb 08 '17 at 16:26
  • 7
    With this solution, I get `Cannot import: GTK+` and `DLL load failed`. – Juergen Jan 24 '19 at 07:51
  • 4
    @Juergen The answer to this is that there is a path mismatch going on. If you were to copy libgirepository-1.0-1.dll which is in your lib directory one directory up (that is the same directory as Meld.exe) and start, you would find things working, – demongolem Apr 11 '19 at 16:03
  • @Juergen See the [upstream issue](https://gitlab.gnome.org/GNOME/meld/issues/267) for description and workarounds. – Franklin Yu May 01 '19 at 15:55
26

Schuess, be careful for space character in directories!

[merge]
    tool = meld
[mergetool "meld"]
    prompt = false
    keepBackup = false
    keepTemporaries = false
    path = C:/Program Files (x86)/Meld/Meld.exe
    cmd = \"/C/Program Files (x86)/Meld/Meld.exe\" \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" \"--output=$PWD/$MERGED\"
GusGold
  • 350
  • 4
  • 16
Martin Dušek
  • 269
  • 2
  • 2
  • 1
    The edits seem to me to have broken the solution. The original revision works for me, so +1. I did find it seems to work without the path line. – vossad01 Jan 28 '14 at 05:00
  • This worked for me when I used `cmd` without `path` and used backticks instead of single quotes, single quotes instead of slash-double quotes. – sq33G Jul 30 '18 at 11:27
  • With Win10 1903 and WSL, I tried a bunch of these config approaches and git could not invoke meld. I ended up symlinking `Program_Files_x86 -> 'Program Files (x86)/'` and used ```[mergetool "meld"] path = /mnt/c/Program_Files_x86/Meld/Meld.exe ``` – Bill Hoag Oct 29 '19 at 22:53
10

I had the exact same problem and found I had to brute force my way to get it to work. Here is what I put in my .gitconfig file. (Note my meld executable is in a different location)

[merge]
    tool = meld
[mergetool "meld"]
        cmd = "/c/Meld/meld/meld.exe $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE --output=$PWD/$MERGED"
schuess
  • 849
  • 9
  • 19
  • Exactly that worked fine for me, with the custom install path I'd picked anyway. It's worth noting that there's a difference between "path", which most guides use, and "cmd" which is specified here. – FauxFaux Feb 24 '13 at 15:40
  • I've tried both yours and Martin's solutions and neither have worked. I think there is something else going on. A window opens and then closes immediately, and then Meld opens with the paths pointing to Meld's installation directory instead of the repo. Could an arg passed to Meld be causing it to die and then it detects the problem and relaunches with the default path? I'm grasping here but I'm not sure how to troubleshoot this... – Nelson Feb 25 '13 at 23:11
  • You sure you're using the meld.exe and not the meld file which is in (I think) a bin folder. I remember having a problem where I used simply the meld file and it launches the application before git has a chance to put the files in the temporary folder. – schuess Feb 26 '13 at 02:36
  • I used your solution, but using the `meld` file in the `bin` directory (I actually renamed the file `meld.py`) and it worked without issue. – Jarrett Nov 22 '13 at 05:11
8

How to use meld as your git difftool in place of git diff (see also the screenshots of meld below):

1. Windows:

Download and install Git for Windows, which includes a "Git Bash" Linux-like terminal accessible via the right-click menu in any folder in Windows Explorer, once you've installed Git for Windows.

Download and install meld from here: https://meldmerge.org/.

Then, to make meld your git difftool, you can use these two commands, inside the Git for Windows bash terminal, (as Arugin says), using the proper path to Meld.exe:

git config --global merge.tool meld
git config --global mergetool.meld.path "C:\Program Files (x86)\Meld\Meld.exe"

OR you can just edit your C:\Users\YOUR_USER_NAME\.gitconfig file directly and add the following to the end of it (notice the mandatory usage of the double-backslashes [\\] here as the path separator!):

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

Now call git difftool in your Git for Windows bash terminal and Meld will open up as your default difftool viewer! If you don't already know: you can open said terminal in Windows by right-clicking in a folder in Windows Explorer and going to --> "Git Bash" or whatever it's called.

2. Linux:

I might as well put the Linux instructions here too for my own reference in one place if nothing else:

For Linux it's even easier:

# 1. install meld
sudo apt update
sudo apt install meld
# 2. edit your ~/.gitconfig file (gedit GUI editor will open)
gedit ~/.gitconfig

Then add to the bottom of the .gitconfig file:

[diff]
    tool = meld

That's it! git difftool now works on Linux Ubuntu!

3. Mac OS

Install Meld on Mac OS: https://superuser.com/questions/360007/how-to-install-meld-with-homebrew-on-mac-osx/1177575#1177575.

Sample screenshots of Meld

https://i.stack.imgur.com/sNR7J.png

(source) enter image description here

Usage of Meld

# 1. In place of `git diff`:
git difftool

# 2. Calling meld directly to compare two files:
meld path/to/file1.txt path/to/file2.txt

Related:

  1. [my answer on my git blametool] Is there git blame gui similar to bzr qannotate?
  2. Download and install meld from here: https://meldmerge.org/
  3. [my answer] How do I make Git use the editor of my choice for commits?
  4. [my repo] https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
  5. Install Meld on Mac OS: https://superuser.com/questions/360007/how-to-install-meld-with-homebrew-on-mac-osx/1177575#1177575
Gabriel Staples
  • 11,777
  • 3
  • 74
  • 108
4

I found a solution in a bug report on the meld installer, on this page:

https://code.google.com/p/meld-installer/issues/detail?id=11

As far as I understand, the problem is that the meld.exe program (which runs meld through the python interpreter) needlessly sets the command's working directory to that of meld.exe. This causes relative paths to be interpreted incorrectly when passed as command line arguments.

The solution is to replace the provided meld.exe with one generated by compiling the meld.ahk file, using AHK2EXe (AutoHotKey script -> exe). Just download the script furthest down the page, as there have been a few version posted there.

star99ers
  • 76
  • 2
  • 3
    The issue tracker wasn't set up to assign the issue to me automatically so I missed that there were comments. For googlers who find this later; this issue has been fixed. – Keegan Oct 02 '13 at 15:45
4

I too faced similar issue.Operating system used is Windows 10 and the following changes worked for me.It seems more like path issue

git config --global mergetool.meld.path "/c/Program Files (x86)/Meld/Meld.exe" <- path to meld here
Pravin
  • 637
  • 2
  • 7
  • 21
3

For some reason, in Windows 10 the PATH environmental variable could not be set properly during the installation, so a strange exception is raised saying that it is not able to find some .dll that are under "C:\Program Files (x86)/Meld/bin" directory.

A workaround for me was, execute in git bash:

export PATH=$PATH:"/C/Program Files (x86)/Meld/lib" 

Or add to windows PATH

C:\Program Files (x86)/Meld/bin
David L.
  • 101
  • 1
  • 3
2

None of the answers worked for me. I ended up with this in the .gitconfig-file:

[merge]
  tool = meld
[mergetool "meld"]
  cmd = 'C:/Program Files (x86)/Meld/Meld.exe' $LOCAL $BASE $REMOTE --output=$MERGED
[mergetool]
  prompt = false

After a git merge mybranch ending with conflicts, you simply type git mergetool and meld opens. After a save, you have to commit in git and the conflicts are resolved.

For some reason, this only worked with Meld 3.18.x, Meld 3.20.x gives me an error.

Jeremy Benks
  • 1,549
  • 2
  • 13
  • 17
0

After trying all of the above, setting Meld to run as administrator worked for me.

  1. Right-click Meld.exe
  2. Go to Properties > Compatibility and select the Run this program as an administrator checkbox

The errors I received referenced temp files like c:\windows\temp\meld-*, which were not being created. Elevating Meld's permissions seems to do the trick as it now works with both git difftool and running manually within Meld.

Drey
  • 131
  • 8