How to use opendiff as default mergetool

孤人 提交于 2019-11-28 09:04:06
Kevin Leary

You'll need to configure opendiff as your global 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

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.)

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

$ 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.

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.

#!/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

Call it like this:

git difftool -d -x gdiff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!