diff · + added · − removed
Text compare
Comparing “red, green, blue” with “red, yellow, blue” line by line gives 1 line added, 1 line removed and 2 unchanged. Paste two texts to see every difference.
- +1 −1 =2
- @@ -1,3 +1,3 @@
Each added line is marked + and each removed line is marked −, as well as coloured, and the changed characters inside a replaced line are highlighted. Small texts compare as you type; the text never leaves this tab.
Scanned by NortonTM Safe Web
At a glance
- Price
- No charge
- Account
- None needed
- Upload
- Not applicable — both texts stay in your tab
- Method
- Longest common subsequence of lines, with changed characters highlighted
- Output
- Coloured and marked lines, or a unified diff with 3 lines of context
- Size limit
- 5,000 lines and 5,000,000 characters per text
A worked comparison and the effect of the options
The tables come from the same code as the tool. The first compares two three-line texts; the second shows how the options change the result for one pair of lines.
| Marker | Line |
|---|---|
| = | red |
| − | green |
| + | yellow |
| = | blue |
| Setting | Lines added | Lines removed |
|---|---|---|
| Exact | 1 | 1 |
| Ignore case | 1 | 1 |
| Ignore whitespace | 1 | 1 |
| Ignore case and whitespace | 0 | 0 |
How to compare two texts
Paste the two texts
Put the older text in the Original box and the newer text in the Changed box. Two short samples are already there. Swap exchanges the two boxes, and Clear empties both.
Choose what counts as a difference
Tick Ignore case to treat “Hello” and “hello” as the same line, and Ignore whitespace to ignore spaces at the ends of a line and repeated spaces inside it. Show only changes folds the unchanged lines away, keeping 3 lines around each change.
Read or copy the difference
Lines marked − exist only in the Original, lines marked + only in the Changed text. Copy the unified diff to paste it into a message or a patch, or download it as a .diff file.
How the comparison works
The two texts are split into lines, and the tool finds the longest common subsequence of lines: the largest set of lines that appear in both texts in the same order. Every line outside that set is reported as removed (only in the original) or added (only in the changed text), so the diff has the fewest changed lines possible. Where a removed line is followed directly by an added one, the characters that differ between the two are highlighted.
A diff works on lines because lines are the unit that code, configuration files and lists change in, and a line comparison stays quick for thousands of lines. A line that moved shows once as removed and once as added; a changed word shows as a replaced line, with the characters highlighted. Line endings are normalised, so a file saved with Windows line breaks matches the same file saved with Unix line breaks. Each text may have up to 5,000 lines and 5,000,000 characters. The unified diff output uses the common format: a --- and +++ header, then @@ hunks with 3 lines of context.
Text compare questions
How does a text diff decide what changed?
It finds the longest common subsequence of lines, meaning the most lines that both texts share in the same order. Lines outside it are marked − if only the original has them and + if only the changed text has them. “red, green, blue” against “red, yellow, blue” keeps red and blue, removes green and adds yellow.
Why does the comparison work on lines and not on words?
Lines are how code, logs, lists and configuration files are organised, and a line-based result is short enough to read. For a replaced line, the characters that differ are highlighted inside it, so a one-word change in a long sentence is easy to spot.
What do the colours and the + and − signs mean?
A green line marked + was added in the Changed text. A red line marked − was removed from the Original. Unmarked lines are the same in both. The signs are printed as well as the colours, so the result is readable without telling red from green.
How do I ignore differences in case or spaces?
Tick Ignore case to compare lines without regard to capitals, and Ignore whitespace to ignore spaces at the start and end of a line and to treat any run of spaces inside it as one space. With both ticked, “Hello World” and “hello world” are the same line.
How large can the two texts be?
Each text may have up to 5,000 lines and 5,000,000 characters. A 5,000-line text compared with a reordered copy of itself is processed in well under a second on a current computer. Above 100,000 characters in total the comparison starts when you press Compare instead of as you type.
What is a unified diff?
It is the text format used by diff and Git. It starts with a --- and a +++ line naming the two texts, then one block per group of changes. A block begins with a header such as @@ -1,3 +1,3 @@, meaning 3 lines from line 1 of the original and 3 lines from line 1 of the changed text, and every line starts with a space, + or −.