Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mereformalities/6060789 to your computer and use it in GitHub Desktop.
Save mereformalities/6060789 to your computer and use it in GitHub Desktop.

Using FileMerge (opendiff) with Git on Mountain Lion

FileMerge (opendiff) can really come in handy when you need to visually compare merging conflicts. Other times it's just a nice visual way to review your days work.

The following method works by creating a simple bash script (git-diff-cmd.sh) that sets us up with the proper command line arguments for Git to pass off files to FileMerge.

Check that your shell can run opendiff. You may need to:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

Create the bash script:

vim ~/dev/bin/git-diff-cmd.sh

Paste the following and save it:

#!/bin/sh 
opendiff "$2" "$5" -merge "$1"

Make the bash script executable:

chmod +x ~/dev/bin/git-diff-cmd.sh

Tell Git (globally) to run our bash script when 'git diff' is issued:

git config --global diff.external ~/dev/bin/git-diff-cmd.sh

Now head over to your Git-aware project directory and issue a git diff /path/to/modified/file.rb and FileMerge will pop up showing you the differences against it and HEAD.

You can also do things like git diff --cached to review all the changes against HEAD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment