Skip to content

Instantly share code, notes, and snippets.

@gwarnes-mdsol
Forked from miner/gdiff
Last active March 16, 2021 04:43
Show Gist options
  • Save gwarnes-mdsol/b0aff96fbb7a4c92e570e7b03daa7e1b to your computer and use it in GitHub Desktop.
Save gwarnes-mdsol/b0aff96fbb7a4c92e570e7b03daa7e1b to your computer and use it in GitHub Desktop.
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
Copy link
Author

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