Skip to content

Instantly share code, notes, and snippets.

@gwarnes-mdsol gwarnes-mdsol/gdiff forked from miner/gdiff
Last active Mar 25, 2017

Embed
What would you like to do?
Use FileMerge as git difftool on Mac OS X
#!/bin/bash
#
# A git difftool for Mac OS X that uses FileMerge from XCode
#
# source: https://gist.github.com/gwarnes-mdsol/b0aff96fbb7a4c92e570e7b03daa7e1b
#
# Setup:
#
# 1. Copy this file to a known path, e.g. $HOME/bin/gdiff
# 2. Make the file executable:
# chmod +x $HOME/bin/gdiff
# 2. Tell git to use this script as the preferred difftool:
# git config --global diff.tool $HOME/bin/gdiff
#
# Usage:
#
# git difftool <git diff arguments>
#
# 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 terminations to issues with git temp files
open -a FileMerge -n -W --args -left "$1" -right "$2" -merge "$dir" ${@:2}
# references:
# http://hints.macworld.com/article.php?story=20070220223441729
# https://gist.github.com/bkeating/329690
# https://gist.github.com/miner/e73fc98a83a8fe05d9ef000d46d68a9f
@gwarnes-mdsol

This comment has been minimized.

Copy link
Owner Author

commented Nov 3, 2016

This version adds support for passing additional command line arguments, such as a branch specification:

git difftool -d origin/master

and provides information on how to configure it to be used by default.

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.