Windows 上的 Git Diff 和 Meld

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20238883/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 09:24:15  来源:igfitidea点击:

Git Diff and Meld on Windows

gitmsysgitgit-diffmelddifftool

提问by Jacob Krieg

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

有没有人让 Meld 在 Windows 上与 Git 一起工作?我正在努力让它发挥作用,但没有成功。

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.1of Git.

我已经安装了 Meld,当我从命令行使用两个文件作为参数调用它时,它会很好地区分它们,因此 Meld 安装正确。但是我不能让它与 Git (Git Diff) 一起工作。我使用的git version 1.8.1.msysgit.1是 Git版本。

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

我尝试了几件事:我创建了一个 shell 脚本,meld.sh

#!/bin/bash
meld.exe "" ""
echo 
echo 

and used it from Git:

并从 Git 使用它:

[diff]
    tool = meld

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

I tried to add it as a difftool like this:

我尝试将其添加为这样的 difftool:

[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:

但它似乎真的不起作用。我还尝试从我的 shell 脚本中回显第二个($2)和第五个($5)参数,但没有输出。我还尝试以多种方式使用批处理脚本:

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 Gituses when diffing to Meld? It's pretty annoying...

但它真的不起作用......我如何Git在与 Meld不同时传递文件使用的两个版本?挺烦人的...

回答by VonC

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

通常,您可以在 Windows 上找到与此 gist类似的示例,meld.exe 在您的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.

你可以在“ Git mergetool with Meld on Windows”中找到更强大的设置,但想法保持不变。



The OP reports in the comments:

OP 在评论中报告:

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

对于difftool,您的命令在 中写入以下配置.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.

一切正常。

回答by mechsin

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.

或者更好的是,如果您在一个锁定的系统上,不允许在路径上胡闹,或者您只是不想污染您的路径空间,您可以将完整路径放入 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.

我也更喜欢我当前的工作代码副本显示在左侧,所以我交换了 $REMOTE 和 $LOCAL 参数。还要注意 \ 到 / 的转换,不要为了转义双引号。

[diff]
    tool = meld
[difftool "meld"]
    cmd = \"C:/Program Files (x86)/Meld/meld/meld.exe\" $REMOTE $LOCAL

回答by Rajeev

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

对于 Windows 7(甚至其他版本的 Windows),在.gitconfig文件中添加这些行。

[diff]

    tool = meld

[merge]

    tool = meld

[difftool "meld"]

    path = C:/Program Files (x86)/Meld/meld/meld.exe

[mergetool "meld"]

    path = C:/Program Files (x86)/Meld/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.

请注意,"即使路径包含空格,也不需要使用。请记住使用正斜杠而不是反斜杠。

回答by Cathy

I tried several variations of trying to set the path with git configto 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-helpand git mergetool --tool-helpnow recognize Meld, and I can choose it as my preferred tool.

我尝试了几种尝试设置路径的变体,git config但无济于事。因为我想从 Git Bash 控制台窗口使用 Meld,所以所做的工作是将路径导出到 Meld 目录,重新启动 Bash shell 和瞧git difftool --tool-helpgit mergetool --tool-help现在识别 Meld,我可以选择它作为我的首选工具。

.profile

。轮廓

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

.gitconfig

.gitconfig

[merge]
    tool = meld
[diff]
    tool = meld

回答by TingQian LI

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

用户从 gitk 调用 diff 的另一个提示(通过右键单击上下文菜单项“External Diff”):

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

上述设置可能会被 gitk 的首选项覆盖。在这种情况下,更改 gitk 菜单EditPreferencesGeneralExternal diffsetting 中的工具。