Text tools

Compare two texts

Paste an original and a changed version to see what was added, removed or edited. Changed lines are highlighted word by word, and unchanged stretches fold away so the differences stand out.

Runs entirely in your browser. Nothing you enter here is uploaded.

How to compare two texts

  1. Paste the earlier version on the left and the later version on the right.
  2. Press Compare (or Ctrl+Enter). A summary says how many lines were added, removed and left unchanged.
  3. Read the result side by side, with removed text in red on the left and added text in green on the right. Within a changed line, the exact words that differ are marked more strongly. Switch to Unified to see a single column, as in a code review.
  4. Tick Ignore spacing if the texts were re-indented or re-wrapped, or Ignore upper/lower case if only capitalisation differs, so those changes do not drown out the real ones.
  5. Press Copy as unified diff to paste the result into an email, a ticket or a patch file.

Long stretches without changes are folded into a single "… unchanged lines …" row, keeping three lines of context around each change.

How the differences are found

Comparing two texts means finding the shortest set of line insertions and deletions that turns one into the other — equivalently, the longest sequence of lines they have in common. This tool uses Eugene Myers' O(ND) algorithm from 1986, the same approach as the default algorithm of git diff. Its running time grows with the size of the text multiplied by the number of differences, so two long documents that differ in a few places are compared almost instantly.

Before running the algorithm, lines that match at the start and end of both texts are set aside, since they cannot be part of a change. If the remaining texts differ in more than 2,000 places, the tool stops refining and reports the remaining region as replaced, which keeps completely different documents from freezing the page.

Word-level highlighting

When a line was edited rather than inserted or deleted, the same algorithm runs again on the words of that pair of lines, so a single changed word lights up instead of the whole line. English is split into words and punctuation; Chinese and Japanese, which have no spaces, are split into individual characters, and neighbouring changed characters are shown as one block.

Unified diff format

The copied text uses the unified format read by git, patch and most code review tools. It starts with the two file names, then one or more hunks. Each hunk header such as @@ -3,5 +3,5 @@ means "five lines starting at line 3 in the original correspond to five lines starting at line 3 in the changed version". Lines beginning with a space are unchanged context, with a minus were removed, and with a plus were added.

Examples

Comparing a, b, c (one per line) with a, x, c gives: a unchanged, b removed, x added, c unchanged — one line added, one removed, two unchanged.

Comparing "the quick brown fox" with "the slow brown fox" on the word level marks only quick as removed and slow as added. For Chinese, 我喜欢苹果 against 我喜欢香蕉 marks 苹果 as removed and 香蕉 as added.

A unified diff of an eight-line file in which line 5 changed from e to X, with two lines of context:

--- old.txt
+++ new.txt
@@ -3,5 +3,5 @@
 c
 d
-e
+X
 f
 g

With Ignore spacing on, a b (two spaces) and a b count as the same line; with Ignore upper/lower case on, Hello and hello do. Windows and Unix line endings are always treated as equal.

Limits

  • Moved text shows as a deletion and an insertion. Line diffs do not detect that a paragraph was moved; you will see it removed in one place and added in another.
  • Plain text only. Formatting in Word or PDF documents — bold, fonts, tracked changes — is not compared. Copy the text out first; for PDFs, the text layer may break lines differently from what you see.
  • The shortest diff is not always the most natural. When several equally short answers exist, the tool picks one, which occasionally pairs up lines differently from how a person would.
  • Very different large texts are reported as a block replacement beyond 2,000 differences rather than analysed line by line.

Frequently asked questions

Is the text I paste uploaded?

No. Both versions are compared inside your browser, and nothing is stored or transmitted.

Can I ignore changes in spacing or indentation?

Yes. Tick Ignore spacing: leading and trailing spaces are ignored and runs of spaces count as one.

What algorithm does it use?

Myers' O(ND) difference algorithm, the approach behind git diff's default mode, with word-level refinement for changed lines.

Can I compare two Word documents?

Copy the text of each document and paste it here. Formatting differences are not detected, only the words.

How do I share the result?

Press Copy as unified diff and paste it anywhere. The format is understood by git, patch and code review tools, and readable as plain text.

Sources and further reading

Guides that use this tool

↵ to open · Esc to close