Skip to content

Instantly share code, notes, and snippets.

@miner
Last active October 26, 2022 18:29
Show Gist options
  • Save miner/e73fc98a83a8fe05d9ef000d46d68a9f to your computer and use it in GitHub Desktop.
Save miner/e73fc98a83a8fe05d9ef000d46d68a9f to your computer and use it in GitHub Desktop.
using FileMerge as git difftool on Mac OS X
#!/bin/bash
# my git difftool, calls FileMerge with project as -merge target
# better than using opendiff
#
# cd to your project dir and and run difftool like this:
# git difftool -d -x gdiff
# 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, avoids issues with git temp files
open -a FileMerge -n -W --args -left "$1" -right "$2" -merge "$dir"
# references:
# http://hints.macworld.com/article.php?story=20070220223441729
# https://gist.github.com/bkeating/329690
@miner
Copy link
Author

miner commented Apr 23, 2016

I call this script "gdiff". Put it somewhere on your $PATH. Note, the -d option is required for this to work correctly. That means do a full directory comparison rather than individual files. Call it like this:

git difftool -d -x gdiff

Of course, you can put that in an alias or bash script to save typing. And there are other git config options you can tweak to make it your default.

@miner
Copy link
Author

miner commented Apr 23, 2016

By the way, FileMerge comes with the Xcode tools. Get Xcode from https://developer.apple.com/xcode/downloads/

@billsacks
Copy link

Thank you for sharing this! I was struggling with how to get git directory diffs with FileMerge - this is the only solution I have seen that works reliably.

@gwarnes-mdsol
Copy link

I've made a couple enhancements to this gist at https://gist.github.com/gwarnes-mdsol/b0aff96fbb7a4c92e570e7b03daa7e1b. To get a diff do:
git diff -r 9607ab015c6c39f9b77a8564126a23e74c890dcd

(Won't it be nice when github allows gist pull requests!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment