kishba.com

Three of my favorite diff tools

Imagine you have two copies of an article, essay, or paper. You could read the first document followed by the second document and rely on your memory to notice the differences. Or you could open up both documents on your computer, place them side-by-side, and scroll down a little on each side to visually compare each line.

That's what I used to do for many years before I learned that diff tools exist. A diff tool lets you remove yourself as the mechanism for spotting changes. The tool will instead handle comparing files (or images or folders of files!) and visually highlight the differences. Advanced tools -- like the ones I'm showcasing below -- offer color coding, navigation shortcuts, and integrations with other tools.

Once I started diffing, I found myself wanting to diff all the things. On my current team, we have a recurring joke that I am our "senior diffing analyst" because I like to use diffing as a way to spot-check my work and compare versions of systems.

Developers are probably most familiar with diffing because of Git and other version control systems. But I have found ways to diff more than just code. I will often run vendor processes that can export text summaries. I will run these processes multiple times or in multiple environments, and then compare the results. If I work on a project that required a lot of configuration in a test environment, I will use a diff tool to verify that I haven't forgotten anything when I finally deploy the project to production. I even find myself diffing excerpts of logs to find what a user might have done differently between attempts.

Here are three diffing tools that I use the most. Could I use just one? Probably. But as you'll see, I have found scenarios where each tool excels.

Kaleidoscope

I use Kaleidoscope more than any other diff tool. My number one use case is reviewing pending changes to files in Git repositories before I commit. I like to make sure I'm not committing any unexpected files that contain secrets and that I haven't left anything hardcoded that I might regret in the future.

I've configured the ksdiff command line tool that comes with Kaleidoscope, and I have installed their provided Git integration. This means Kaleidoscope is only a few commands away:

# review all pending files within a git repository
# difftool defaults to use a cli diff, but it can be configured to launch Kaleidoscope or other diff tools!
git difftool

# stage some files
git add README.md

# review files and changes I have already staged
# this is my last chance to spot regrettable mistakes!
git difftool --staged

# everything that was staged is good? what are you waiting for, commit!
git commit

Beyond Compare

Before Kaleidoscope was acquired by its most recent publisher, it went awhile without any updates, and I honestly feared its demise. I had also started a new day job where I couldn't use a Mac-only tool like Kaleidoscope. My work PC was preinstalled with some tools recommended by a previous developer including Beyond Compare and WinMerge. Although I initially preferred WinMerge, three things brought Beyond Compare to the top of my favorite tools list:

  1. Beyond Compare is cross-platform. Imagine my surprise when I was reading one of my favorite Apple sites, Six Colors, and they featured Beyond Compare, an application I had assumed was Windows-only! I now run Beyond Compare on both my PC and Mac.
  2. Plugins for XML files. I have configured the "XML sorted" and "XML tidied" plugins so I can compare XML files that are generated by some of the vendor systems I help support at my day job. This means no matter what order the tags of an XML file are written, I can compare two XML files and know exactly what is the same or different between environments or versions.
  3. Incredible subdirectory support. I love to compare installations of vendor software. This includes before & after upgrades and between our multiple test environments. Kaleidoscope can compare directories of files, but when I have huge directories of files, I often switch to Beyond Compare because it's never crashed on me. Plus, did I mention it's cross-platform?

diff

When I find myself on someone else's computer or using SSH to control a remote server, I don't have the luxury of Kaleidoscope or Beyond Compare. Thankfully, the command line tool diff is usually already installed. It's also the only tool in this list that is free.

diff might seem rudimentary, but it can be combined with other chains of commands to do just about anything I need all from the command line.

# This is a contrived example, but imagine outputting the results of other commands
# like ls, cat, and grep from different folders or versions of software to temporary files that you run through diff!
echo "hello,\nthis is version 1" > file1.txt
echo "hello,\nthis is version 2" > file2.txt
diff file1.txt file2.txt

# 2c2
# < this is version 1
# ---
# > this is version 2