What is a diff?
A diff (short for difference) is a comparison of two versions of a text that shows the smallest set of changes needed to turn the first into the second. Text that appears only in the new version is shown as added, usually in green. Text that appears only in the old version is shown as removed, usually in red with a line through it. Everything else is unchanged.
Diff tools have been used by programmers since the 1970s, when the diff command was written for Unix. Today the same idea powers “track changes”, version history in online documents, and code review on sites like GitHub.
Word, character or line?
A diff can compare text in different-sized pieces, and choosing the right one makes the result much easier to read.
| Mode | Best for | Example result |
|---|---|---|
| Words | Essays, articles, contracts, emails | “a |
| Characters | Short strings, codes, spotting typos | “rec |
| Lines | Code, lists, CSV and configuration files | Whole lines marked + or − |
A character comparison of two paragraphs that were heavily rewritten produces a confusing mess of tiny changes. A line comparison of prose shows whole paragraphs as changed when only one word is different. Word mode is the right default for most writing.
How a diff works
Under the hood, a diff tool looks for the longest common subsequence: the longest sequence of words (or lines, or characters) that appears in both texts in the same order. Everything that's part of that sequence is unchanged; everything else is an addition or a deletion.
The most widely used method is an algorithm published by Eugene Myers in 1986. It's fast because it searches for the answer with the fewest edits first, so two documents that are mostly the same are compared almost instantly. It's the algorithm behind Git's default diff and the text difference checker on this site.
How to compare two documents step by step
- Copy the original version into the left box of the text difference checker, and the new version into the right box.
- Choose a mode. Use Words for prose and Lines for code or lists.
- Hide noise. Tick Ignore extra spaces if the texts were formatted differently, and Ignore case if capitalization doesn't matter.
- Read the summary (words added, words removed and how similar the texts are) to judge the size of the changes.
- Review each change in the highlighted result.
Comparing documents in Word and Google Docs
- Microsoft Word: open the Review tab and choose Compare → Compare…. Pick the original and revised documents, and Word creates a new document showing the changes as tracked changes.
- Google Docs: open File → Version history → See version history to see changes between saved versions. To compare two separate files, use Tools → Compare documents.
These built-in tools keep formatting, but they need both files in the same format. Pasting plain text into an online diff is quicker when the versions come from different places, such as an email and a PDF.
Tips for accurate comparisons
- Clean both versions first. Text copied from PDFs often has line breaks in different places, which shows up as changes. Run both through the text cleaner with Fix broken lines turned on.
- Compare like with like. Make sure both versions include the same sections, or the diff will show whole sections as removed.
- Watch for moved text. A diff shows a moved paragraph as deleted in one place and added in another.
- For lists, use a list comparison. If the order doesn't matter, Compare Two Lists tells you which items are in one list, the other or both, regardless of order.
Privacy
Many people compare contracts, HR documents or unpublished work. The text difference checker on this site runs entirely in your browser, so neither version is uploaded to a server.