MiServe DevTools

Your lid

Pin tools here. They are saved in this browser.

Text Diff Checker

Compare two texts line by line, see what was added, removed and changed inside each line, and copy the result as a unified diff.

Runs in your browser. Nothing you paste is uploaded.

About this tool

How the comparison works

The comparison looks for the shortest list of lines to remove from the first text and lines to add to it that turns it into the second. Finding that list is the same problem as finding the longest common subsequence: the longest series of lines that appear in both texts in the same order. This tool uses the algorithm Eugene Myers published in 1986, the one behind GNU diff and the default in Git, in its linear-space form, so memory use stays proportional to the size of the texts.

When a removed line and an added line sit at the same place in a changed block, the two are compared again word by word and the words that differ are highlighted. If the two lines have little in common, they are shown as a plain removal and addition, because highlighting nearly everything would say nothing.

Reading the result

A line marked − exists only in the original text, and a line marked + exists only in the changed text. A changed line therefore appears twice: once removed, once added. The two columns of numbers are the line numbers in the original and in the changed text. The markers carry the meaning; the colours only repeat it.

The unified view puts everything in one column, which is the order a patch file uses. The side by side view keeps each text in its own column and aligns the lines that correspond.

The unified diff format

Copy as unified diff produces the format of diff -u and git diff. Changes are grouped into hunks with three unchanged lines of context around them. Each hunk starts with a header such as @@ -1,7 +1,8 @@, which reads: seven lines starting at line 1 of the original correspond to eight lines starting at line 1 of the changed text.

The line \ No newline at end of file is part of the format. It appears when a text does not end with a line break, so that a patch can reproduce the file exactly. The views on the page ignore that difference, because a last line that looks identical should not be reported as changed.

Questions

Is the text I compare uploaded anywhere?

No. The comparison is done by JavaScript in your browser tab. The tool makes no network request with what you paste, and the site's security policy blocks requests to any other host.

Why is a line marked as changed when it looks the same?

The difference is usually invisible: spaces at the end of the line, a tab instead of spaces, a non-breaking space, or an accented letter stored as two characters instead of one. Turn on the option to ignore white space changes to rule out the first three.

Can I apply the copied diff with patch?

Yes. Save it to a file and run patch with the name of the file to change, for example: patch notes.txt changes.diff. If you copied the diff with an ignore option turned on, the ignored differences are not in it, so the patched file will not match the changed text exactly.

How large can the texts be?

Texts of a few thousand lines compare in a fraction of a second. The page draws at most 5,000 rows, while the copied diff always contains every change. For two very long texts with almost nothing in common the search is cut short and the result may be longer than necessary.

More in Text