Diff-ing commands on Mac
February 29th, 2008 | by Joe |There are several tools to compare files for changes out there for Mac OS X. I’ll cover a few here. The first and most basic is diff. From the command line, it looks like this:
diff -u old_file new_file
Where of course old_file is the old suspected filename, and new_file is the new one. This will give you a quick glance at what is new. Each line of difference in the new file will be preceded by a plus (+) symbol, and each difference in the old one will be preceeded by a minus (-) Last saved timestamps will appear at the very top of the output.
A cool trick - if you use TextMate, you can pipe your diff output to it and take advantage of TextMate’s fancy-schmansy code coloring:
diff -u old_file new_file|mate
Shift + Control + Option switches Textmate to the Diff bundle, and Shift + Control + Command + D will give you access to the context menu for all of the diff commands. Great for you Lightning Ruby Ninja™ coders out there who insist on never letting the tips of your fingers leave your keyboards.
If you have the XCode Developer Tools installed, you get a second option installed: opendiff, laced with a GUI app called FileMerge:
opendiff old_file new_file
What is cool about this is that if you run opendiff from the command line, FileMerge takes over and shows you your differences with sexy Mac-ness, replete with an array of search and code merging commands at your disposal. That’s hot.
If you like BBEdit, and who doesn’t, you have bbdiff at your disposal too:
bbdiff old_file new_file
BBEdit has a file comparison and merging utility built in which does not suck at all.
Extra Coolness for Dreamweaver users: Select opendiff or bbdiff in your prefereces to compare files with their corresponding GUIs this way:
- Dreamweaver > Preferences > File Compare
- Click Browse
- Select bbdiff or opendiff from the file dialog, click OK, and enjoy.
Lusty. So there’s a few options for finding out what your colleague did to break your perfect code. Happy diff-ing!
Tags: BBEdit, code, compare, diff, Dreamweaver, FileMerge, merge, opendiff, programming, TextMate, webdev
3 Responses to “Diff-ing commands on Mac”
By Alderete on Mar 1, 2008 | Reply
There’s a brand new file comparison tool released for the Mac, called Changes. It sports a better algorithm than the one used by FileMerge / opendiff / diff, a spiffy Mac-dedicated UI, and terrific integration with TextMate (among other tools). I learned about it on the TextMate weblog, where there’s a discount code for $10 off the price:
http://blog.macromates.com/2008/changes-filemerge-replacement/
Worth checking out.
By Patrick on Mar 1, 2008 | Reply
Another nice application for diffing is Changes at changesapp.com
It integrates into TextMate and BBEdit as well as the command-line.
By Joe on Mar 4, 2008 | Reply
Wow - Changes looks awesome! Love the integration with TextMate + Subversion features.