Text Diff
checker.
Paste two versions of a text and see each word or line that was added or removed.
- Added lines
- 2
- Removed lines
- 1
- Unchanged lines
- 2
Similarity is twice the lines in common divided by the lines in both texts. One changed word marks a whole line, so by words these are 90% alike.
Differences
A plus sign marks a line only in the changed text. A minus sign marks a line only in the original.
Where the changes fall
2 lines added and 1 line removed around 2 lines left as they were, shown in reading order.
Every change, by line
| Change | Old lines | New lines | Removed | Added |
|---|---|---|---|---|
| 1Old 1New 1 | 1 | 1 | The quick brown fox | The quick red fox |
| 2Old NoneNew 4 | None | 4 | Nothing | The end. |
Similarity at each level
| Compared | Similarity |
|---|---|
| By lines | 57% |
| By words | 90% |
| By characters | 89% |
A finer level keeps more of a changed line, so the score usually rises from lines to words.
As two lists
- Only in the original
- 1
- Only in the changed text
- 2
- In both
- 2
Each line as an item
| Item | |
|---|---|
| The quick brown fox | Original only |
| The quick red fox | Changed only |
| The end. | Changed only |
| jumps over the lazy dog. | Both |
| It was a sunny day. | Both |
Each line counts as one item. Order and repeats do not matter here.
Keyboard shortcuts
- C copies the differences.
- S swaps the two texts.
- M moves between lines, words and characters.
- They work when no box or button has focus.
How it's worked out
The tool looks for the longest common subsequence: the largest set of lines, words or characters that appear in both texts in the same order. Hunt and McIlroy set out the idea in 1976 for the Unix diff program, and showed that keeping the most lines unchanged is the same goal as making the fewest edits.
The tool fills in a table of matches for every pair of pieces. P is the length of the best match so far, for the first i pieces of one text and the first j of the other.
Whatever falls outside that common thread is marked as removed from the original or added in the new version. The score is the same ratio that Python uses in its comparison library, with M as the pieces in common and T as the pieces in both texts together. Identical texts score 1, and texts with nothing in common score 0.
The level you choose decides what a piece is. A line must match in full, a word is any run without a space, and a character is one letter or digit. Spaces count as pieces in word mode, so the score moves a little when spacing changes. Ignore case and Ignore spacing work like the -i and -b options of diff.
Worked examples
A shopping list that changed
Apples, bananas and cherries became apples, blueberries, cherries and dates. By lines, that is 1 removed, 2 added and 2 unchanged, for a score of 57%: twice 2 matches over 7 lines.
Read as two lists, 2 items are in both, bananas is only in the first, and blueberries and dates are only in the second.
A meeting note with a new day and time
Compared by words, only Tuesday and 3 are marked as removed, with Thursday and 4 in their place. That is 2 words out and 2 in.
The level changes the score a lot. By lines this pair scores 0%, because the one line differs. By words it scores 87%, and by characters 93%, since Tuesday and Thursday share most of their letters.
Code that was only re-spaced, plus one new line
With spacing counted, 2 lines are marked as removed and 3 as added, which hides the real change. With Ignore spacing on, 0 lines are removed and only 1 is added: the new call to save on line 3.
Reading your result
A high score does not mean a small change. In a contract, one added "not" can reverse a clause and still leave the page at 99%. Use the score to see how much was rewritten, and read the marked text to judge what it means. Pay special attention to small words, dates and figures.
For a long document, start by lines to see which paragraphs changed at all. Then move to words to read the edits inside them. Turn on Ignore spacing first, because reflowed text can mark nearly every line.
A moved paragraph shows up as removed in one place and added in another, since a common subsequence only keeps pieces in the same order. If you need moves marked, git can color them with its --color-moved option. When order does not matter at all, such as two lists of names, read the list comparison instead, which ignores order and repeats.
Formatting is not part of plain text. Bold, fonts and tracked changes in a Word file do not survive a paste, so only the wording is compared.
Common mistakes
- Comparing in the wrong direction. Removed and added depend on which text goes first. Swap them if the marks look reversed.
- Blaming line endings. Files from Windows and Unix end lines differently. Line mode treats both alike, so that pair scores 100%. Word and character modes count those endings as characters, so use lines there.
- Reading punctuation as a word change. Word mode treats "day." and "day" as different words. Switch to characters to see that only the period moved.
- Expecting a very long text to work by characters. Very long pairs are refused at the finer levels to keep the page fast. Compare by lines, or split the text into sections.