git difftool Beyond Compare 4 不区分本地和远程

git difftool Beyond Compare 4 not diffing local with remote

我正在使用 CYGWIN 和 Beyond Compare 4 专业版。我设置了以下 .gitconfig 文件:

[diff]
    tool = bc3
[difftool "bc3"]
    path = c:/program files/beyond compare 4/bcomp.exe
[merge]
    tool = bc3
[mergetool "bc3"]
    path = c:/program files/beyond compare 4/bcomp.exe

在对本地文件进行小改动后,我 运行 在 CYGWIN 中执行以下命令:

git difftool

Beyond Compare 4 正确启动,但仅左侧为全红色。右边是空的。

我希望通过对本地更改(左)与远程更改(右)进行简单比较来启动它。

我以为这是默认行为?是否还有我遗漏的其他设置,或者仅此设置可用

您列出的配置应该在 Windows 命令提示符中与 Git for Windows 2.12.1.windows.1 一起正常工作。我还没有用 Cygwin 测试过它。

如果您使用的是 Cygwin 提供的 Git 版本,从 https://git-scm.com/ 切换到 Git 的 Windows 版本可能会有所帮助。过去,Cygwin 的 Git 版本明显落后于官方 Windows 版本。要检查您的 Git、运行 "git --version".

版本

我能够通过将 .gitconfig 文件配置为以下内容来解决我的问题:

[difftool "bc3"]
     cmd = \"c:/program files/beyond compare 4/bcomp.exe\" "$(cygpath -w $LOCAL)" "$REMOTE"

这会在执行 git difftool

时带来本地和远程的差异

我不得不修改上面的

git config --system difftool.bc.cmd '"c:/program files/beyond compare 4/bcomp.exe" "$(cygpath -w $LOCAL)" "$(cygpath -w $REMOTE)"'

更进一步,与 mergetool 类似:

git config --system mergetool.bc.cmd '"c:/program files/beyond compare 4/bcomp.exe" "$(cygpath -w $LOCAL)" "$(cygpath -w $REMOTE)" "$(cygpath -w $BASE)" "$(cygpath -w $MERGED)"'

至于core.editor,如果你想使用Sublime Text,你需要使用包含以下命令的外部脚本~/git-editor.sh

cygpath --windows $@ | sed 's/\/\\/g' | tr '\n' '[=12=]' | xargs -0 -n1 /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe -n -w

我修改了上面的

然后将其添加到您的 git core.editor 配置中:

git config --system core.editor "~/git-editor.sh"

如果您不为编辑器使用外部脚本,如果您尝试将 $cygpath 放入 core.editor 配置中,git 将导致 Sublime text 打开两个文件git 会将 "wrong path" 文件名附加到 core.editor 设置的末尾。