【问题标题】:How to use opendiff as default mergetool如何使用 opendiff 作为默认的合并工具
【发布时间】:2012-11-23 00:52:10
【问题描述】:

您好,我正在尝试使用 opendiff 作为 git mergetool,但是当我运行 mergetool 时,我收到以下错误消息:

合并工具 opendiff 不能作为 'opendiff' 使用

我做错了什么?它以前工作得很好,但是自从我安装了一个新的硬盘后它就不再工作了:(

【问题讨论】:

  • 这是在 OSX Snow Leopard 上。
  • 清理 opendiff 并重新安装?我希望你已经尝试过了

标签: git mergetool opendiff


【解决方案1】:

您需要将 opendiff 配置为您的全局 merge.tool:

# 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 什么时候还没有被发现,但很难理解你最终会如何陷入这种情况。
  • 我之前可以运行opendiff,但两天前我安装了rvm并安装了最新的Ruby 2.6.3...然后opendiff停止工作,报告“xcode-select:错误:工具 'opendiff' 需要 Xcode,但活动开发者目录 '/Library/Developer/CommandLineTools' 是命令行工具实例”。你xcode-select 的第一行解决了这个问题......但它只是感觉发生了什么很神秘
【解决方案2】:

确保您已安装 XCode。 (如果您使用的是 git,那么您可能使用的是 brew,在这种情况下您可能已经安装了 XCode。)

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

$ git mergetool -t opendiff

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

【讨论】:

    【解决方案3】:

    git 支持 --dir-diff (-d) 执行目录 diff,在 FileMerge 中看起来不错。但是,使用带有 --dir-diff 的 opendiff 存在一些小问题。 opendiff 没有 --merge 目标预设,git 会过早删除临时文件以保存更改。我的解决方法是使用一个小的 bash 脚本来调用 FileMerge。我叫它gdiff

    #!/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 只会阻止它命令,直到您按“保存”而不是直到程序退出)
    猜你喜欢
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-12-23
    • 1970-01-01
    • 2010-09-07
    • 2011-01-05
    • 2015-04-17
    • 1970-01-01
    相关资源
    最近更新 更多