Git mergetool with Meld on Windows

2019-01-21 00:03发布

问题:

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?

回答1:

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!



回答2:

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'


回答3:

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"


回答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.



回答5:

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


回答6:

You can use these two commands (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:

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

Now call git difftool in Git Bash for Windows and Meld will open up as your default difftool viewer.



回答7:

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.



标签: git meld