如何将opendiff设置为默认合并工具

23

你好,我正在尝试将opendiff作为git mergetool使用,但当我运行mergetool时,出现以下错误信息:

合并工具opendiff不可用作 'opendiff'

我做错了什么?之前它一直正常运行,但自从我安装了新的硬盘后就无法正常工作了 :(


这是在OSX Snow Leopard上。 - CorpusCallosum
清理Opendiff并重新安装?我希望你已经尝试过了。 - Ram
3个回答

31

您需要将opendiff配置为全局合并工具:

# locate xcode utilities
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

# set "opendiff" as the default mergetool globally
git config --global merge.tool opendiff
如果您收到 Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo 的提示,请打开XCode并接受许可证即可解决问题。

我猜当git还没有被找到时,但很难理解你可能会如何陷入这种情况。 - Tommy
以前我可以运行opendiff, 但是两天前我安装了rvm并安装了最新的Ruby 2.6.3……然后opendiff停止工作了,报告了 "xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance"。你的第一行xcode-select修复了这个问题...但是它感觉很神秘,不知道究竟发生了什么。 - nonopolarity

17

请确保您已经安装了XCode。(如果您正在使用git,则可能使用brew,在这种情况下,您可能已经安装了XCode。)

一次性的解决方案是告诉git你想要使用的工具:

$ git mergetool -t opendiff

如果要将opendiff设置为默认工具,您需要在git配置文件中设置“merge.tool”变量。


2
Git支持--dir-diff(-d)执行目录差异,这在FileMerge中看起来很好。然而,使用--dir-diff时,opendiff存在一些小问题。opendiff没有--merge目标预设,并且git会过早删除临时文件以保存更改。我的解决方法是使用一个小的bash脚本调用FileMerge。我称之为。
#!/bin/bash
# find top level of git project
dir=$PWD
until [ -e "$dir/.git" ]; do
  if [ "$dir" == "/" ]; then
    echo "Not a git repository" >&2
    exit 1;
  fi
  dir=`dirname "$dir"`
done
# open fresh FileMerge and wait for termination
open -a FileMerge -n -W --args -left "$1" -right "$2" -merge "$dir"

https://gist.github.com/miner/e73fc98a83a8fe05d9ef000d46d68a9f

这样调用它:
``` git difftool -d -x gdiff ```

哇,这真的按照预期工作了!(opendiff从未按预期工作,因为它在完成之前返回,并且将管道传输到cat只会阻止命令,直到您按“保存”而不是程序退出) - StackedCrooked

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