Sourcetree无法打开Diffmerge以解决合并冲突问题。

6
最近我重新安装了macOS。我已经安装了Sourctree和diffmerge,并将diffmerge设置为默认合并工具。但是,每当我选择“解决冲突->打开外部合并工具”时,sourcetree会打开其等待视图,然后立即关闭它。
我的Sourctree设置页面:

enter image description here

这是我的根目录下.gitconfig文件,当sourcetree为我配置diff merge时,它的样子是这样的:
[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
3个回答

21

当我通过pkg install安装diffmerge而不是安装程序时,就会发生这种情况。显然,这不会配置您的bash以识别diffmerge命令,因此您必须设置diffmerge路径(或更新bin配置)。

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

sourcetree中的设置页面

enter image description here

Diff

Command: /usr/local/bin/diffmerge Arguments --nosplash "$LOCAL" "$REMOTE"

Merge

Command: /usr/local/bin/diffmerge Arguments --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命令行参数的更多信息:

Diff:https://sourcegear.com/diffmerge/webhelp/sec__clargs__diff.html

Merge:https://sourcegear.com/diffmerge/webhelp/sec__clargs__merge.html


1
请注意,“Diff Command”可能会因diffmerge二进制文件所在的位置而有所不同,在我的情况下,它是:/Applications/DiffMerge.app/Contents/MacOS/DiffMerge。 - Osmar
对我来说,我无法使用--nosplash选项。它会在“/var/folders”中弹出一个“未找到”的错误。但是一旦我为自定义diffmerge选项去掉了--nosplash,它就可以工作了。另外,我没有引用变量。 - gregthegeek
我遇到的问题在这里提出: https://dev59.com/VNX8oIgBc1ULPQZFAApl#76001320 移除--nosplash解决了它。 - gregthegeek

2
我按照 DiffMerge 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。

Sourcetree preference pane, showing the Diff tab, with DiffMerge selected for the Visual Diff Tool and Merge Tool options

(可选)您可能想在其他参数之前,将--nosplash添加到这两个命令中,以避免启动画面(正如@saren-inden所推荐的那样)。即:
$ 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\""

0

我遇到了同样的问题。当我点击外部差异时,DiffMerge也没有启动。

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

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

还没有尝试合并。


如果我这样做并重新启动SourceTree,它会恢复重复的部分。如何彻底删除它? - esbenr
@esbenr 根据Saren Inden的解决方案,定义自定义差异工具。只需将diffMerge的正确命令和参数复制到sourcetree设置中即可。 - zhezha

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接