What a diff shows
A diff describes the smallest practical set of changes that turns one text into another: which lines were removed, which were added, and which stayed the same. Comparing two versions by eye works for a handful of lines but quickly becomes unreliable, while a diff highlights every change, including a single changed character in a long configuration file.
Diffs are at the heart of version control. Every Git commit, pull request review, and patch file is a diff. The same technique is useful well outside code: comparing contract revisions, API responses from two environments, or exported settings before and after an upgrade.
How diff algorithms work
Most diff tools are built on the idea of a longest common subsequence: find the longest sequence of lines that appears in both texts in the same order, then report everything else as insertions or deletions. Eugene Myers published an efficient algorithm for this in 1986, and it remains the default in Git and many other tools because it finds a minimal edit script quickly for typical inputs.
A minimal diff is not always the most readable one. When code blocks are moved or many lines are similar, such as closing braces, the algorithm can align the wrong lines. Variants such as patience diff and histogram diff first anchor on lines that are unique in both files, which often produces output that matches how a person thinks about the change.
Side-by-side, unified, and intra-line views
A side-by-side view places the original and modified text in two columns with matching lines aligned, which is the easiest way to review changes in context. A unified view merges both versions into one column, marking removed lines with a minus and added lines with a plus. It is the format of patch files and of git diff output, and it is more compact for long files.
Line-level diffs only tell you that a line changed. Intra-line highlighting goes a step further and marks the exact words or characters that differ within a changed line. This is invaluable when a long line differs by one value, such as a port number or a feature flag.
Reducing noise in comparisons
Many differences are not meaningful. Trailing whitespace, changed indentation, Windows versus Unix line endings, and letter case can make two equivalent files look completely different. Options that ignore whitespace or case let the real changes stand out.
Structured formats need special care. Two JSON documents can contain identical data while differing in key order and formatting, so a plain text diff reports changes on almost every line. Normalizing both sides first, by parsing and re-serializing them with sorted keys and consistent indentation, reduces the diff to genuine differences in values. The same applies to XML attribute order and formatting.
When reviewing a long diff, navigate change by change rather than scrolling, and read deletions as carefully as additions. Removed lines are where accidental regressions most often hide.
Practical comparison workflows
Comparing configuration across environments is one of the most valuable uses of a diff. Export the settings from staging and production, normalize their format, and compare them before a release: missing feature flags, different timeouts, and outdated endpoints show up immediately.
For API work, capture the response of the same request before and after a change and compare them to see exactly which fields were added, removed, or changed. For documents, compare drafts to review an editor's changes or to confirm that only the intended clauses of an agreement were modified. In each case, removing irrelevant differences such as timestamps or request IDs first keeps attention on the changes that matter.