fixmint

How to find what changed between two versions of a text

· 4 min read

To find what changed between two versions, a compare tool lines the two texts up and marks what was added and what was removed. Start with a line comparison for code, configuration and lists. Switch to a word comparison when a sentence changed inside a paragraph that otherwise stayed the same, because a line comparison will mark the whole paragraph.

Compare textWhat changed between versions?Open

How a diff works

A diff looks for the longest common subsequence (LCS): the longest run of items that appear in both versions in the same order. The items do not have to sit next to each other. Everything in that common run is unchanged. Everything else is either an addition, which appears only in the new version, or a deletion, which appears only in the old one.

Here is a small example. The old text is "A B C D" and the new text is "A C X D". The longest common run is "A C D", so B is a deletion and X is an addition. The comparison tool does this for long documents too, which is why it can show you a precise list of changes rather than two blocks of text side by side.

Line or word comparison

  • Line comparison suits code, configuration files, lists and anything with one item per line. A changed line appears as a removal followed by an addition.
  • Word comparison suits essays, contracts and any prose. It shows that one word changed without marking the whole sentence.
  • Character comparison can help with IDs and short strings, but it is too noisy for ordinary prose.

Worked example: one word that matters

Consider two versions of a clause:

  • Old: "The supplier shall deliver the goods within 14 days of the order."
  • New: "The supplier may deliver the goods within 30 days of the order."

A line comparison marks the whole sentence as removed and added, which hides what changed. A word comparison shows exactly two changes: "shall" became "may", and "14" became "30". Two words changed, and the rest of the sentence is the same. The first change alters the meaning, since an obligation has become an option, so the word comparison is the one to read carefully.

Ignore whitespace and case

Whitespace and case differences often hide the real change, so most compare tools let you ignore them:

  • Ignore trailing spaces when text was copied from an editor that adds them.
  • Ignore case when a list was typed by several people. Do not ignore case where it matters, such as a configuration key or a file name on Linux.
  • Ignore blank lines when only the spacing was reflowed.

For example, "Total: 100" and "total: 100" have the same content if case is ignored. In a file where keys are case-sensitive, they are different settings, so you should not ignore case there.

Edge cases

  • Moved paragraphs. A diff keeps the original order, so a paragraph that moved appears as a deletion in one place and an addition in another. Look for it by eye, or compare the two sections separately.
  • Reflowed text. If the new version was re-wrapped at a different width, a line comparison reports changes that are not real. Use a word comparison, or remove the line breaks first with fix pasted text.
  • Hidden characters. Invisible characters appear as changes even when nothing visible has changed. Remove them before comparing.
  • Large rewrites. When almost everything changed, a diff is hard to read. Compare one section at a time.

How to read the output

Start with the removals and then the additions. Check numbers, dates, names and negatives first, because a single changed digit can matter more than a page of rewording. In the contract example, two changed words in a sentence of 13 words is a small edit, and a word comparison makes it easy to spot. If you are comparing two versions of your own writing, a word count comparison can also show whether the new version has grown or shrunk.

When the two versions come from different people, label them, such as "draft 3" and "draft 4", and keep the older file unchanged. Reading the changes in order, from top to bottom, lets you follow how an argument or a clause moved through the edits. It is slower than scanning for the largest change, but it is less likely to miss a small one.

Quick answers

What is a diff?

A diff is the list of what was added and removed between two versions, calculated from the longest sequence the two versions share.

Should I compare by line or by word?

Use lines for code and lists, where each line is a separate item. Use words for prose, where a single sentence may have changed inside a paragraph.

Why does a diff show whole paragraphs as changed?

Usually because line breaks, spaces or hidden characters differ. Ignore whitespace, reflow the text or remove the hidden characters, then compare again.

Cover of How to Remain Valuable When Intelligence Becomes CheapHow to Remain Valuable When Intelligence Becomes Cheap

224 pages on the human, economic and strategic advantages that stay scarce when AI can do most cognitive work.

$3.84 Get it on Gumroad →