Comparing files: FileMerge, opendiff, and BBEdit

Comparing two text files is one of those fundamental tasks which never seems to go away. Whenever Apple releases an update to XProtect’s data files, I have to compare the new with the old to work out what has changed, for instance. For many of us, similar comparisons need to be made even more often. This article looks at Apple’s free FileMerge tool for doing this, and more, and the Find Differences… feature in the Gold Standard text editor, BBEdit.

The first fact to note is that, if you’re a command line wizard, you don’t have to compare files the easy way. If you enjoy mixing sudoku with Scrabble, macOS comes with a full implementation of the standard Unix command diff.

For us lesser mortals, there’s a free app, FileMerge, which is bundled with Apple’s Xcode SDK. Installing a whole development environment just to get a tool to find differences might seem excessive, but there are many other good reasons to have Xcode and its tools to hand.

Apple used to deliver FileMerge and other Xcode support apps in a separate folder, but they’re now buried away inside the Xcode.app folder, in Contents/Applications, so you’ll probably want to install the app in your Dock, make an alias to it, or prepare some other means of ready access. There are two official ways to open it: one is inside Xcode itself, from the Xcode menu, the other is, bizarrely, a command in Terminal, such as
opendiff testOld.plist testNew.plist
which puts testOld.plist in the left view and testNew.plist in the right.

compareff01

If you’d rather run FileMerge another way, then it will open with this dialog, in which you select the files to be compared using the Left… and Right… buttons.

compareff02

What you then get is a superb comparison between the chosen files, with easy navigation, syntax-based colouring, and the ability to merge in changes wherever you wish.

FileMerge is unusual in that it offers two extensions to basic document comparison: ancestors and directory comparison.

Ancestors cope with the common event of forking or branching: two different versions are derived from a common ancestor. By specifying the common ancestor to FileMerge, it can select when to take changes from the left or right file. This is almost a three-way comparison, and when FileMerge finds all three files at odds with one another, it puts a red border around a difference to draw attention to it.

Comparing directories is essentially performing a series of comparisons between matching files in two directory trees. You can use an ancestor, and if you want to merge the directories, you need to provide another directory into which to save the merged result. Although occasionally useful, comparison of directories is aimed more at specialists maintaining Xcode and similar projects.

Despite FileMerge inevitably being installed here with Xcode, I choose to use the Find Differences… feature in BBEdit instead. I have used BBEdit ever since I can remember using a text editor on the Mac, and take for granted its many very powerful features.

compareff03

The options for each comparison are set when you start, and cover most which you might wish for.

compareff04

The differences window comparing two files isn’t quite as graphically whizzy as FileMerge’s, but I find it extremely clear in use. This example shows a block of text which is present in the righthand file, but missing from that on the left – the same situation as shown above for FileMerge. The listing of differences in the view at the foot gives an excellent overview, and is simple to navigate.

I haven’t yet discovered any feature equivalent to FileMerge’s ancestors, although that may be my disinterest in getting my head around three-way comparisons. Comparing whole folders is significantly simpler, and performed in the same basic window, with a file navigator added at the left. FileMerge puts the navigator into a separate window, from which file-by-file comparisons are opened into its regular comparison window, which is more fussy and clutters the screen.

Finding and working with differences between text files can be a very confusing task. No matter how systematic you are at putting the ‘old’ version on one side, you can easily apply changes in the wrong direction, and make other silly mistakes. I find BBEdit’s differences window a firmer base on which to work; FileMerge is just as powerful and effective, but in my hands at least it can becoming more confusing.

When you need to compare other types of document, life quickly gets more complex. Nisus Writer Pro, for example, contains a Compare Documents script which performs a text-based comparison in a third window, which is useful, but not a patch on the likes of FileMerge or BBEdit. Microsoft Word also has a built-in comparison, but it is telling that many serious Word users still export documents for comparison as text instead.

Most document processors, such as Word and Pages, now encourage users to track changes and use annotations to work around shortcomings in file comparison. Although those features have their uses, they can’t compare with FileMerge or BBEdit in this respect.