text diff
Compared line by line in the page, neither version uploaded.
The short answer
Compared by longest common subsequence over lines, which is what makes the answer useful: insert a line at the top and it reports one insertion, where a line-by-line comparison would mark every line after it as changed. Whitespace counts, because in a config file it sometimes matters.
Two versions side by side, then the differences. It compares by longest common subsequence, so inserting one line reports one insertion rather than marking everything after it as changed.
The formula
longest common subsequence over lines, walked back into a list of changes
Worked examples
- A line inserted
- one addition
- A line edited
- one removal and one addition
- Lines reordered
- reported as a move out and a move in
Reference table
| Change | Reported as | Why |
|---|---|---|
| Line inserted | One addition | The rest still matches |
| Line edited | One removal, one addition | Lines are compared whole |
| Trailing space added | A change | Whitespace can matter |
| Lines swapped | One removal, one addition | A diff has no idea of a move |
How to use it
- 01Paste the originalInto the Before box. Nothing is sent anywhere.
- 02Paste the new versionInto the After box. The diff appears underneath as you type.
- 03Read the resultAdditions in green, removals in red, unchanged lines in grey.
Also searched for
Searches that land here include text diff, compare two texts, diff checker, text comparison tool and find differences in text.
How the comparison works
Longest common subsequence
The algorithm finds the longest run of lines, in order, that appears in both versions, then reports everything else as added or removed. That is what makes the output useful. A naive comparison that walks both sides in step reports one inserted line at the top as a change to every line in the file, which is true and useless.
Reading the result
Green with a plus is in the new version only. Red with a minus is in the old version only. An edited line shows as both, because lines are compared whole. A long block of unchanged grey between two changes is a hint that the two versions share more than they appear to.
Where it stops
Two thousand lines a side. The comparison builds a table of one side against the other, so the work grows with the product of the two lengths, and the output stops being readable long before it stops being fast. For anything larger, a proper diff tool with context folding is the right instrument.
Questions people ask
Why compare lines rather than words?
Because the question people bring here is what changed between two versions, and lines are the unit changes arrive in. A word-level diff of a long document produces a speckled mess that is harder to read than the two originals. For a single sentence, comparing by eye is faster than any tool.
Does whitespace count as a difference?
Yes. A trailing space is a change, because in a config file, a Makefile or a YAML document whitespace sometimes is the meaning. If you want to ignore it, strip it first — the duplicate-line and sort tools on this site both trim as they go.
Why is a moved line shown as both removed and added?
Because a diff has no concept of a move. It finds the longest sequence common to both sides and reports everything else as an insertion or a deletion, so a line that travelled from the top to the bottom looks like one of each. Every diff tool does this; the good ones just draw it more prettily.