Diff checker

Paste the original and the changed text to see every added and removed line.

This tool runs in your browser. We never send what you type or paste to a server.

How it works

The checker finds the longest common subsequence of lines between the two texts, the same idea behind diff and Git. Lines only in the original are marked as removed, lines only in the new text as added, and everything else is unchanged.

Turn on Ignore whitespace to skip differences in indentation and trailing spaces, useful when comparing reformatted code.

Example

Original:

timeout: 30
retries: 3
log_level: info

Changed:

timeout: 60
retries: 3
log_level: debug

The result marks two lines as changed and highlights just 30 → 60 and info → debug inside them, so you do not have to compare the lines by eye.

The longest common subsequence, step by step

A subsequence keeps lines in order but may skip some. For the original a b c d and the new text a c d e (one letter per line), the longest sequence of lines both share in the same order is a c d. Everything outside it is a change: b was removed and e was added. The checker builds a table of LCS lengths for every pair of positions and walks it from the top, which is exact but grows with lines × lines; that is why texts over about 3,000 lines each are refused rather than freezing the page.

An LCS diff has no idea of a moved line. Moving one import to the top shows as an addition at the top and a removal further down:

+ import json
  import os
  import sys
- import json

How changed words are highlighted

Within each block of changes, the first removed line is paired with the first added line, the second with the second, and so on. For each pair the checker strips the characters the two lines share at the start and at the end and highlights what is left, as one stretch per line:

- const total = price * qty;
+ const total = price * qty * (1 + vat);

Only * (1 + vat) is highlighted on the new line. When a line changes in two places far apart, everything between them is highlighted too; that is a sign to look at the line as a whole.

Gotchas

  • Final newline: a followed by a line break and a without one differ by an empty last line. Editors and Git treat a missing final newline as a change too (\ No newline at end of file).
  • Line endings: Windows (CRLF) and Unix (LF) line breaks are treated the same here, so they never show as changes. Git and diff do see them.
  • Ignore whitespace collapses every run of spaces and tabs to one space and trims both ends, so indentation and trailing spaces no longer count, but ab and a b still differ. That sits between diff -b (which still sees leading spaces) and diff -w (which ignores all spaces).
  • Reordered data: two JSON files with the same keys in a different order look completely different. Sort keys first in the JSON formatter; for CSV or log lines, sort both texts the same way.

Diff on the command line

Unified diff is the format patches and code review use: - for removed, + for added, and @@ hunk headers with line numbers.

diff -u old.txt new.txt | tail -n +3     # tail drops the two header lines with file names and times
# → @@ -1,3 +1,3 @@
# → -timeout: 30
# → +timeout: 60
# →  retries: 3
# → -log_level: info
# → +log_level: debug

Git can diff any two files, even outside a repository, and show changed words inline:

git -c core.autocrlf=false diff --no-index --word-diff=plain old.txt new.txt | tail -n +6
# → timeout: [-30-]{+60+}
# → retries: 3
# → log_level: [-info-]{+debug+}
printf 'a  b\n' > w1.txt; printf 'a b \n' > w2.txt
diff -q w1.txt w2.txt > /dev/null || echo differ          # → differ
diff -q -b w1.txt w2.txt > /dev/null && echo same         # → same   -b ignores changes in the amount of space

Python's difflib writes the same format (n=0 means no context lines) and can score similarity:

old = ['timeout: 30', 'retries: 3', 'log_level: info']
new = ['timeout: 60', 'retries: 3', 'log_level: debug']
for line in difflib.unified_diff(old, new, 'old', 'new', lineterm='', n=0):
    print(line)
# → --- old
# → +++ new
# → @@ -1 +1 @@
# → -timeout: 30
# → +timeout: 60
# → @@ -3 +3 @@
# → -log_level: info
# → +log_level: debug
print(round(difflib.SequenceMatcher(None, 'colour', 'color').ratio(), 3))   # → 0.909   similarity from 0 to 1

PowerShell: Compare-Object lists lines that are only on one side (<= original, => new). It compares sets, not positions, so a moved line is not reported at all.

$old = 'timeout: 30', 'retries: 3', 'log_level: info'     # Get-Content old.txt for a file
$new = 'timeout: 60', 'retries: 3', 'log_level: debug'
Compare-Object $old $new | ForEach-Object { "$($_.SideIndicator) $($_.InputObject)" }
# → => timeout: 60
# → => log_level: debug
# → <= timeout: 30
# → <= log_level: info

Questions

Is the comparison line by line?

Yes. Changed lines show as one removed line and one added line, with the changed words highlighted.

Can I compare JSON?

Yes. For the clearest result, format both with the JSON formatter (with "Sort keys" on) first.

Can I compare two JSON files?

Yes. For the clearest result, format both first with the JSON formatter using the same indent, so that only real changes show up rather than spacing.

Why is a moved block shown as removed and added?

A line-based LCS diff only knows that lines exist on one side and not the other. Git can detect moved lines with git diff --color-moved, but the underlying diff is still a removal plus an addition.

Can I compare two files rather than pasting?

Open each file in a text editor, copy its content and paste it into the matching box. Nothing is uploaded. For files too large to paste, use diff -u old new or git diff --no-index old new on the command line.

What does @@ -1,3 +1,3 @@ mean in a diff?

It is a hunk header in unified diff format: the hunk covers 3 lines starting at line 1 of the old file and 3 lines starting at line 1 of the new file. Lines starting with - were removed, + added, and a space means unchanged context.