How to use opendiff and git diff and not needing to install the whole Xcode app?

2.7k views Asked by At

After upgrading to MacOS Mojave, my git and opendiff stopped working (my opendiff is usually invoked by git diff).

I was able to get git working, by using the following two lines:

xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools

but opendiff and git diff still doesn't work. It seems one solution is to install the Xcode app, which is huge (said to be taking up 10GB on the hard drive). I checked Spotlight and typed FileMerge, and was able to find it, which should be the same as opendiff, and was able to use ps ax to find the path /Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge. But then, using git diff, I actually used a bash script to invoke

#!/bin/sh 
/usr/bin/opendiff "$2" "$5" -merge "$1" | cat

(see this github article about how to set up git-diff-cmd.sh)

so I changed that second line to:

/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge "$2" "$5" -merge "$1" | cat

but it doesn't work. So FileMerge exists, and it looks like opendiff is FileMerge. Can git diff be made to work without needing to install the whole Xcode app?

2

There are 2 answers

0
nonopolarity On

This may seem like a hack, and in fact it seems like it is using an existing installation of XCode:

I did

cd /Applications/Xcode.app
find . -iname '*opendiff*'

and was able to find

./Contents/Developer/usr/bin/opendiff
./Contents/Developer/usr/libexec/git-core/mergetools/opendiff

The first file is a binary file, and the second one is actually a script, so I changed my bash script git-diff-cmd.sh to the following:

#!/bin/sh 
/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff "$2" "$5" -merge "$1" | cat

and git diff can successfully invoke opendiff to do a visual diff.

1
matt On

Can git diff be made to work without needing to install the whole XCode app?

Install the whole BBEdit app instead. It’s small and efficient and does a very nice visual diff.