在 Windows 上使用 Meld 的 Git 合并工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14821358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git mergetool with Meld on Windows
提问by Nelson
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.
在 Linux 中,我最喜欢的合并工具是 Meld,我在使用或配置它以与 Git 一起工作时没有遇到任何问题。但是,在 Windows 中,情况就不同了。
First, I installed Meld from a bundle I found here: https://code.google.com/p/meld-installer/
首先,我从我在这里找到的一个包中安装了 Meld:https: //code.google.com/p/meld-installer/
Then, I configured my .gitconfig like so to support Meld as the default mergetool
然后,我像这样配置了我的 .gitconfig 以支持 Meld 作为默认的合并工具
[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.
因此,当我遇到冲突时,我会使用 git difftool 并且 Meld 实际上会打开。但是,Git 写入以传递给 diff 工具的文件的路径不正确。例如,即使 Git 在存储库目录(我从中调用 git mergetool 的位置)生成 BASE、LOCAL 和 REMOTE 文件,Meld 也会尝试打开可执行文件目录中的每个文件。
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.
Meld 没有打开 C:\repo\roses.txt.LOCAL.2760.txt,而是尝试打开 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?
有没有人遇到过这个问题或知道如何配置 Git / Meld 以在 Windows 中正常工作?
回答by Arugin
Why do you not use git bash for Windows?
为什么不在 Windows 上使用 git bash?
After install meld simply:
简单地安装meld后:
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!
就这样!
回答by Martin Du?ek
Schuess, be careful for space character in directories!
Schues,注意目录中的空格字符!
[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\"
回答by schuess
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)
我遇到了完全相同的问题,发现我必须用蛮力才能让它工作。这是我放在 .gitconfig 文件中的内容。(注意我的 meld 可执行文件位于不同的位置)
[merge]
tool = meld
[mergetool "meld"]
cmd = "/c/Meld/meld/meld.exe $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE --output=$PWD/$MERGED"
回答by Gabriel Staples
Windows:
视窗:
You can use these two commands (as Arugin says)--using the proper path to Meld.exe:
您可以使用这两个命令(如 Arugin 所说)——使用 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:
或者您可以直接编辑您的C:\Users\YOUR_USER_NAME\.gitconfig
文件并将以下内容添加到它的末尾:
[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.
现在调用git difftool
Windows 版 Git Bash,Meld 将作为您的默认 difftool 查看器打开。
Linux:
Linux:
UPDATE 20 Sept. 2019:
- I might as well put the Linux version here too for my own reference in one place if nothing else:
2019 年 9 月 20 日更新:
- 如果没有别的,我也不妨将 Linux 版本放在这里供我自己参考:
For Linux it's super easy too:
对于 Linux,它也非常简单:
sudo apt update
sudo apt install meld
gedit ~/.gitconfig # edit your ~/.gitconfig file (gedit GUI editor will open)
Then add to the bottom of the .gitconfig file:
然后添加到 .gitconfig 文件的底部:
[diff]
tool = meld
That's it! git difftool
now works on Linux Ubuntu!
就是这样!git difftool
现在适用于 Linux Ubuntu!
Related:
有关的:
- Download and install meld from here: https://meldmerge.org/
- How do I make Git use the editor of my choice for commits?
- https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
回答by Pravin
I too faced similar issue.Operating system used is Windows 10 and the following changes worked for me.It seems more like path issue
我也遇到了类似的问题。使用的操作系统是 Windows 10,以下更改对我有用。似乎更像是路径问题
git config --global mergetool.meld.path "/c/Program Files (x86)/Meld/Meld.exe" <- path to meld here
回答by star99ers
I found a solution in a bug report on the meld installer, on this page:
我在此页面上的 meld 安装程序的错误报告中找到了一个解决方案:
https://code.google.com/p/meld-installer/issues/detail?id=11
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.
据我了解,问题在于meld.exe 程序(通过python 解释器运行meld)不必要地将命令的工作目录设置为meld.exe 的工作目录。当作为命令行参数传递时,这会导致相对路径被错误解释。
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.
解决方案是将提供的meld.exe 替换为通过编译meld.ahk 文件生成的meld.exe,使用AHK2EXe(AutoHotKey 脚本-> exe)。只需下载页面最下方的脚本,因为那里已经发布了几个版本。
回答by David L.
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.
出于某种原因,在 Windows 10 中,在安装过程中无法正确设置 PATH 环境变量,因此引发了一个奇怪的异常,说它无法找到“C:\Program Files (x86)/”下的某些 .dll Meld/bin”目录。
A workaround for me was, execute in git bash:
我的解决方法是,在 git bash 中执行:
export PATH=$PATH:"/C/Program Files (x86)/Meld/lib"
Or add to windows PATH
或者添加到windows PATH
C:\Program Files (x86)/Meld/bin
回答by Jeremy Benks
None of the answers worked for me. I ended up with this in the .gitconfig-file:
没有一个答案对我有用。我在 .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.
在git merge mybranch
以冲突结束后,您只需键入git mergetool
并融合打开即可。保存后,您必须在 git 中提交并解决冲突。
For some reason, this only worked with Meld 3.18.x, Meld 3.20.x gives me an error.
出于某种原因,这只适用于 Meld 3.18.x,Meld 3.20.x 给了我一个错误。
回答by Drey
After trying all of the above, setting Meld to run as administrator worked for me.
在尝试了上述所有方法后,将 Meld 设置为以管理员身份运行对我有用。
- Right-click Meld.exe
- Go to Properties> Compatibilityand select the
Run this program as an administrator
checkbox
- 右键单击 Meld.exe
- 转到“属性”>“兼容性”并选中
Run this program as an administrator
复选框
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.
我收到的错误引用了c:\windows\temp\meld-*
未创建的临时文件,例如。提升 Meld 的权限似乎可以解决问题,因为它现在可以同时使用git difftool
并在 Meld 中手动运行。