Skip to content

Instantly share code, notes, and snippets.

@iwill
Forked from gwarnes-mdsol/gdiff
Created March 16, 2021 04:43
Show Gist options
  • Save iwill/2f7013f2ea7dc7007c56ca107c37c15b to your computer and use it in GitHub Desktop.
Save iwill/2f7013f2ea7dc7007c56ca107c37c15b 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment