Long before software had a "diff" command, English and American contract lawyers were marking up drafts the same way: crossing out deleted text and underlining new text in red ink, a practice still called "redlining" or a "blackline" today — Microsoft Word's own "Compare Documents" feature is a direct descendant of that legal tradition, not the other way around.
Longest common subsequence
A software diff formalizes what redlining does by hand: it finds the longest common subsequence (LCS) of lines shared between two versions of a text. Lines inside that subsequence are treated as unchanged; everything else is marked as removed from the old version or added to the new one. The result is a minimal set of edits, not just any sequence of deletions and insertions that happens to work.
How to read the result
A typical diff marks removed lines with one symbol (often -, shown in red) and added lines with another (+, shown in green). A line that "changed" in the everyday sense is technically rendered as a deletion of the old line plus an insertion of the new one — diff has no built-in notion of editing a line in place.
Why line-by-line comparison isn't always intuitive
Insert a single new line in the middle of a text and a line-by-line diff can report every following line as "changed," because the algorithm can't always tell an insertion apart from a wholesale replacement. Legal redlining runs into the same failure mode: renumbering a single contract clause can make an automated document comparison flag the entire rest of the agreement as rewritten.
Why you'd use this
- Checking exactly what changed between two versions of a config file or document.
- Reading a pull request by following the logic of the underlying diff algorithm.
- Comparing a script's output before and after a refactor to confirm nothing regressed.
Line-level diff vs. character-level diff
Line-by-line comparison suits code and config files, but for prose or a long sentence where a single word changed, it marks the whole line as removed and re-added. A word- or character-level diff inside the line pinpoints exactly which word changed — at the cost of significantly higher computation on large documents.