Working with file diffs in Sourcetree

Aug 2, 2012 07:57 · 228 words · 2 minute read

I’ve been using Sourcetree as a graphical Git client for a while, and it’s working pretty well and is free-as-in-beer. The UI is a bit on the noisy side, but the workflow seems to fit nicely with the way I use Git.

Sourcetree has been designed to work with a range of graphical diff clients - for no other reason than inertia, I’ve stuck with using opendiff, but this needs configuring. As it’s something that doesn’t need doing very often, I tend to forget the settings, and for some reason Google has a lot of conflicting advice. This is my setup, which Just Works (for the moment).

The Sourcetree “Visual Diff Tool” and “Merge Tool” settings are both set to opendiff, while the arguments are both $LOCAL $REMOTE -merge $MERGED

This is also reflected in my global .gitconfig file:

[difftool "sourcetree"]
    cmd = opendiff $LOCAL $REMOTE -merge $MERGED
    path = 
[mergetool "sourcetree"]
    cmd = opendiff $LOCAL $REMOTE -merge $MERGED
    trustExitCode = true
[mergetool]
    keepBackup = false

The keepBackup = false flag stops opendiff littering the place with .orig files, although I’ve also got these mentioned in my .gitignore_global file.

Selecting the ‘External Diff’ option in Sourcetree will open up FileMerge - then a save and quit will trigger Sourcetree as recognising that the clash has been resolved. From there, it’s just a matter of committing the changed files.