TIL: Comparing Files Side By Side With diff -y
diff shows what changed between two files. diff -y shows it side by side so you see both versions at once.
diff -y config-v1.json config-v2.json
Output has two columns. The left is the first file, the right is the second. Differences are highlighted with markers in the gutter.
diff -y --suppress-common-lines old-config.json new-config.json
Show only the lines that differ. When two config files are mostly the same, this cuts the noise to just the actual changes.
diff -y -W 120 --suppress-common-lines file-a.js file-b.js
The -W flag sets the output width in characters. Widen it for files with longer lines so columns do not truncate.
Can I see line numbers?
Add –left-column to show line numbers. The output format is slightly different but the side by side layout is preserved.
Is diff -y on macOS?
The BSD version of diff on macOS supports -y. Install GNU diff with brew install diffutils for more formatting options.