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
@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