Mon, 8 February 2010

Very often, before I commit something in git, I take a quick look at the changes that I’ve made in my source code by comparing the file to the previous version. This helps to prevent mistakes, but most of all it helps me come up with a good description of my changes to use as the commit message. The Developer folder has a great application for doing that: FileMerge. It’s located in /Developer/Applications/Utilities/ and can also be used from the command line through the opendiff tool (in /Developer/usr/bin/).

Here’s how I use FileMerge with git. I’ve made a very simple shell script to help me out. I call it mydiff.

git show $2:$1 > /tmp/mydiff
/Developer/usr/bin/opendiff /tmp/mydiff $1

You can use it with either one or two arguments. I typically use it with the name of my source file as the only argument.

$ mydiff MySourceFile.m

This will compare my edited (uncommitted) source file to the most recently committed version from the git repository. If you want to compare it to other versions, you can provide a second argument.

$ mydiff MySourceFile.m BETA-1.0

This example will compare the current version with the commit that’s tagged as BETA-1.0. The second argument can also be a commit name or any other statement that refers to a specific version in git.

Blue Crowbar — Apps for iOS and OS X