How to use opendiff as default mergetool
Asked Answered
L

3

23

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

The merge tool opendiff is not available as 'opendiff'

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

Laodicea answered 5/12, 2012 at 8:36 Comment(2)
This is on OSX Snow Leopard.Laodicea
clean opendiff and re-install again ? I hope you already tried itModie
B
33

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

Bandbox answered 2/9, 2014 at 14:18 Comment(2)
I guess when git isn't already being found, but it's difficult to understand how you might end up in that situation.Live
I could run opendiff before, but two days ago I installed rvm and installed the latest Ruby 2.6.3... and then opendiff stopped working, reporting "xcode-select: error: tool 'opendiff' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance". Your first line of xcode-select fixed the issue... but it just feel so cryptic what was happeningCarriole
M
18

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.

Mixon answered 8/3, 2013 at 0:39 Comment(0)
M
2

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

Monro answered 25/4, 2016 at 13:8 Comment(1)
Wow, this actually works as it should! (opendiff never worked as expected because it returns before finishing, and piping to cat only blocks it command until you press "Save" and not until the program quits)Indican

© 2022 - 2024 — McMap. All rights reserved.