Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

HOWTO: Using FileMerge (opendiff) with Git on OSX


HOWTO: Using FileMerge (opendiff) with Git on OSX

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 ( that sets us up with the proper command line arguments for Git to pass off files to FileMerge.

  1. Open the bash script for editing:

    vi ~/bin/
  2. Paste the following code:

    /usr/bin/opendiff "$2" "$5" -merge "$1"
  3. Make the bash script executable:

    chmod +x ~/bin/
  4. Tell Git (globally) to run our bash script when 'git diff' is issued:

    git config --global diff.external ~/bin/

Now head over to your Git-aware project directory and issue a git diff /path/to/modified/ 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.

#!/bin/sh` should be


Thanks, yllan. Fixed.

I think the leading "\" of "#!/bin/sh" also need to be deleted. The correct version should be

/usr/bin/opendiff "$2" "$5" -merge "$1"


Thanks. Fixed it. Not sure why that was.

This is awesome, thanks very much!

j-kan commented

You can also use git difftool.


j-kan, blindly trying git difftool on another machine of mine did not do anything. shrug I'll keep it in mind though. Thanks.

j-kan commented

Huh... here's what it does for me:

beton:pgm1 kan$ git difftool diagnosis.clj 
merge tool candidates: opendiff kdiff3 tkdiff xxdiff meld kompare gvimdiff diffuse ecmerge p4merge araxis emerge vimdiff

Viewing: 'pgm1/diagnosis.clj'
Hit return to launch 'opendiff': 

...and hitting return does exactly what it says. I'm running, if that matters....

Very confusing terminology. "Choose Left" moves the arrow from the right to the left. This seems that the code on the right goes into the chosen code on the left. - Please provide an improvement to help the user.

Anyone know what diff git natively uses? I like it's terminal output and want to make it my system default.

Hi, how do I paste the code in in step 2?
I try to paste it in, but I get an error that reads:

"E486: Pattern not found: usr"

I guess I don't understand how to use VI, it is not intuitive for me, but I want to make this work. Before I had git setup to use opendiff as the mergetool and it worked great. Somehow it stopped working and I don't know how to get it back. Thanks.


Frizlab commented

There are two mode when you're in vi. The "command" mode in which you type commands, and the edition mode. To enter the edition mode, you should type "i", or "a". Then you can paste the code. To leave the edition mode, hit the escape key. To quit and save the changes, type ":x" then the return key while in command mode.

This works great but is there any way to make the git diff command line not wait until FileMerge quits?
I made the following modification so that a copy is made of the temp file that git generates so that & can be called on opendiff.

TMPFILE=$(mktemp /tmp/output.XXXXXXXXXX)
# Copy the temp file that git generates
# So that the command line can exit
cp $5 $TMPFILE
/usr/bin/opendiff "$2" "$TMPFILE" &

This works great when I test it directly from the shell.

./ ignored test.txt ignored ignored test2.txt 

but when asking git to do a diff I don't regain control of the terminal until I quit FileMerge

git diff 263f..4aaa complete.cpp 

After looking at this more closely it appears the git diff behavior is different depending on whether FileMerge is already running. So if FileMerge is running before a call to git diff then it works.

Here is a fish shell version for working with a temp file.


set -l TMPFILE (mktemp /tmp/output.XXXXXXXXXX)

# Copy the temp file that git generates
# So that the command line can exit
cp $argv[5] $TMPFILE

function event_git_diff --on-event git_diff_event
  /usr/bin/opendiff $argv[1] $argv[2] &

emit git_diff_event $argv[2] $TMPFILE

difftool did the right thing for me, too.

% git --version
git version (Apple Git-47)

Problem for me with difftool is that it will ask for merge file when saving.
Problem for me with this script is that opendiff will open new diffs before I had time to save/quit.

If someone knows how to fix sequential diffs where git will wait for the first file to be saved/quit before diffing another file + have merge path set I'd be really greatful.

I had this behaviour with svn using filemerge and:

But can't seem to replicate it with git.

@mcormier I think you can just put & after the command to put in the background.

For anyone interested, this is how I solved it (using git difftool):

    tool = opendiff
    prompt = false
[difftool "opendiff"]
    cmd = /usr/bin/opendiff \"$LOCAL\" \"$REMOTE\" -merge \"$MERGED\" | cat
jianlin commented

if you are using Bash, then add

export PATH=$PATH:~/bin

to your ~/.bashrc too.

worked like a charm, thanks!

Thanks guys!
For me i preferred using difftool over external, since i have some other CLI tools that rely on std output from "git diff" command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.