Skip to content

Instantly share code, notes, and snippets.

@miner miner/gdiff
Last active Nov 30, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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

This comment has been minimized.

Copy link
Owner Author

commented Apr 23, 2016

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

@billsacks

This comment has been minimized.

Copy link

commented Sep 28, 2016

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

This comment has been minimized.

Copy link

commented Nov 3, 2016

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
You can’t perform that action at this time.