git 如何使用 opendiff 作为默认合并工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13719122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:02:48  来源:igfitidea点击:

How to use opendiff as default mergetool

gitmergetoolopendiff

提问by CorpusCallosum

Hi I am trying to use opendiff as the git mergetool, but when I run mergetool I get this error message:

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

The merge tool opendiff is not available as 'opendiff'

合并工具 opendiff 不可用作“opendiff”

What am I doing wrong? It was working fine before, but since I installed a new harddrive it's not working anymore :(

我究竟做错了什么?它以前工作正常,但自从我安装了新硬盘后,它不再工作了:(

回答by Kevin Leary

You'll need to configure opendiff as your global merge.tool:

您需要将 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

If you get Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo, opening XCode and accepting the license fixes the issue

如果你得到了Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo,打开 XCode 并接受许可证可以解决这个问题

回答by cogell

Make sure you have XCode installed. (If you are using git then you probably using brew, in that case you probably already have XCode installed.)

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

A one-off solution is to tell git what tool you want to use:

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

$ git mergetool -t opendiff

As far as setting up opendiff as your default tool, you need to set the "merge.tool" variable in your git config file.

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

回答by miner49r

git supports --dir-diff (-d) to perform a directory diff, which looks good in FileMerge. However, there are a couple of minor problems using opendiff with --dir-diff. opendiff doesn't have a --merge target preset, and git will drop the temp files too soon to save changes. My work-around is to use a little bash script to invoke FileMerge. I called it gdiff.

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 "" -right "" -merge "$dir"

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

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

Call it like this:

像这样调用它:

git difftool -d -x gdiff

git difftool -d -x gdiff