Sourcetree 无法为合并冲突打开 Diffmerge

Sourcetree fails to open Diffmerge for merge conflicts

最近我全新安装了 macOS。我已经安装了 Sourctree 和 diffmerge,并将 diffmerge 设置为默认的合并工具。出于某种原因,每次当我 select 'Resolve Conflicts -> Open External Merge Tool' sourcetree 打开它的等待视图并直接关闭它时。

我在 sourcetree 中的设置页面:

当 sourcetree 为我配置 diff merge 时,我的 root .gitconfig 是这样的:

[core]
    excludesfile = /Users/[username]/.gitignore_global
[user] 
    name = ---- -----
    email = -----@-----.--
[commit]
    template = /Users/[username]/.stCommitMsg
[credential]
    helper =  !/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java -Ddebug=false -Djava.net.useSystemProxies=true -jar /usr/local/Cellar/git-credential-manager/2.0.4/libexec/git-credential-manager-2.0.4.jar

[difftool "DiffMerge"]
[mergetool "DiffMerge"]
[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = /usr/local/bin/diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    trustExitCode = true
    cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
[difftool "sourcetree"]
    cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge --nosplash \"$LOCAL\" \"$REMOTE\"
path = 
[mergetool "sourcetree"]
    cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
    trustExitCode = true

当通过 pkg install 而不是安装程序安装 diffmerge 时,这发生在我身上。这显然不会将您的 bash 配置为知道命令 diffmerge,因此您必须设置 diffmerge 的路径(或更新您的 bin 配置)。

为了解决这个问题,我手动配置了 Visual Diff Tool 和 Merge Tool(好处是您可以在每次启动时禁用令人讨厌的启动画面)。

sourcetree 中的设置页面

差异

命令:/usr/local/bin/diffmerge 参数 --nosplash "$LOCAL" "$REMOTE"

合并

命令:/usr/local/bin/diffmerge 参数 --nosplash --merge --result="$MERGED" "$LOCAL" "$BASE" "$REMOTE"

--nosplash 参数是可选的,但可以防止弹出窗口(在我看来是无用的),您在开始工作之前总是必须关闭它。

Git 配置文件:

[core]
    excludesfile = /Users/[username]/.gitignore_global
[user]
    name = ---------
    email = ---------@------.--
[commit]
    template = /Users/[username]/.stCommitMsg
[credential]
    helper = !/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/bin/java -Ddebug=false -Djava.net.useSystemProxies=true -jar /usr/local/Cellar/git-credential-manager/2.0.4/libexec/git-credential-manager-2.0.4.jar

[difftool "DiffMerge"]
[mergetool "DiffMerge"]
[diff]
    tool = diffmerge
[difftool "diffmerge"]
    cmd = /usr/local/bin/diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
    tool = diffmerge
[mergetool "diffmerge"]
    trustExitCode = true
    cmd = /usr/local/bin/diffmerge --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
[difftool "sourcetree"]
    cmd = /usr/local/bin/diffmerge --nosplash \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /usr/local/bin/diffmerge --nosplash --merge --result=\"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"
    trustExitCode = true

有关 diffmerge 命令行参数的更多信息:

差异:https://sourcegear.com/diffmerge/webhelp/sec__clargs__diff.html

合并:https://sourcegear.com/diffmerge/webhelp/sec__clargs__merge.html

我按照 DiffMerge Settings for OS X 文档页面上的说明解决了这个问题,它是:

首先确认 /usr/local/bin/diffmerge 存在。 如果您使用 PKG 安装程序,它会在安装 /Applications/DiffMerge.app 时安装。 如果您使用的是 DMG 文件,请参阅 Extras.

安装说明

以下命令将更新您的 .gitconfig 以让 GIT 使用 DiffMerge:

$ git config --global diff.tool diffmerge
$ git config --global difftool.diffmerge.cmd
    "/usr/local/bin/diffmerge \"$LOCAL\" \"$REMOTE\""

$ git config --global merge.tool diffmerge
$ git config --global mergetool.diffmerge.trustExitCode true
$ git config --global mergetool.diffmerge.cmd 
    "/usr/local/bin/diffmerge --merge --result=\"$MERGED\"
        \"$LOCAL\" \"$BASE\" \"$REMOTE\""

然后我可以通过选择 Sourcetree 中的菜单选项来使用 DiffMerge

(Optional) 您可能希望在其他参数之前将 --nosplash 添加到这两个命令中,以避免启动画面([=18= 也推荐]).即;

$ git config --global diff.tool diffmerge
$ git config --global difftool.diffmerge.cmd
    "/usr/local/bin/diffmerge --nosplash \"$LOCAL\" \"$REMOTE\""

$ git config --global merge.tool diffmerge
$ git config --global mergetool.diffmerge.trustExitCode true
$ git config --global mergetool.diffmerge.cmd 
    "/usr/local/bin/diffmerge --nosplash --merge --result=\"$MERGED\"
        \"$LOCAL\" \"$BASE\" \"$REMOTE\""

我遇到了同样的问题。当我单击 External Diff.

时,DiffMerge 也没有启动

问题好像出在.gitconfig文件中DiffMerge的路径: cmd = /Applications/DiffMerge.app/Contents/MacOS/DiffMerge/Contents/MacOS/DiffMerge ....

如果你检查路径/Applications/DiffMerge.app/Contents/MacOS/DiffMerge,它实际上不是一个目录而是一个文件。似乎 SourceTree 在路径上添加了两次 /Contents/MacOS/DiffMerge。我删除了重复的部分,External Diff 开始工作。

没试过合并。