Sponsor
Now Playing
- Alix Perez – I'm Free 2 hours ago
- Alix Perez – Intersections 2 hours ago
- Alix Perez – Forsaken 2 hours ago
- Glen E Ston – Ouroboros (Original Mix) 2 hours ago
- Black Sun Empire – Everything 3 hours ago
How to use FileMerge with Git as a Diff Tool on OSX
November 16, 2009,
1,243 views
As I’m migrating from Subversion brainwaves I’ve been slowly adapting my workflow into Git’s. Problem was i was finding it hard to double check changes in my working folder to that of what was previously committed. In other words I missed the love of FileMerge.
So I began puttering around on the internet and found people writing scripts for git’s external diff editor. But they were missing one important element, the location of OpenDiff to save to! So I did this:
Firstly we need to make the script that git will run when it runs it’s diff. To do this run:
vi ~/git-diff-cmd.sh
Then we will drop some script in here which basically routes the diff statements generated by Git to the OpenDiff application
#!/bin/sh /usr/bin/opendiff "$2" "$5" -merge "$1"
Notice the “-merge "$1"” this is the destination to save to. Before hand with other people’s code you would have to manually select the save path. But i did a man opendiff on it to realise all it was, was setting the merge path!
Anyhow. Save that via pressing “shift + ZZ” Saved! Next we need to make that file executable via “chmod +x”
All that is left is to tell Git to use this script as it’s diff editor, which will then invoke the FileMerge (OpenDiff) program. To do that type in:
git config --global diff.external ~/git-diff-cmd.sh
Now how i check my staged files with the previous commit would be:
git diff --cached
Which would then open up all the staged files and allow me to choose which one i wanted to keep or not
Categorised under Programming
3 Comments
Nice, simple and effective!
Thanks for a great post.
Thank you, thank you, thank you
Thanks! This was really helpful! I modified your code to use TextWrangler as the diff tool instead:
http://odbol.posterous.com/use-textwrangler-as-a-diff-and-merge-tool-for