OmniFeed Search

Diff checker

Paste two versions of a text into the boxes to see which lines were added, removed, or left the same. The checker compares whole lines, so changing one letter shows up as one line removed and one added. It runs in your browser; nothing you enter is uploaded.

How the comparison works

The checker looks for the longest list of lines that both texts share in the same order, called the longest common subsequence. Those lines count as unchanged. Every other line of the original counts as removed, and every other line of the changed text counts as added.

The example already in the boxes has three lines in both texts. Changing "Add two eggs." to "Add three eggs and a pinch of salt." shows as one line removed and one added. "Let it cool before slicing." is new, so the total is 2 added, 1 removed, and 3 unchanged.

To find that list, the checker uses the algorithm Eugene Myers published in 1986 in An O(ND) Difference Algorithm and Its Variations, which Git and GNU diff also use by default. Its running time grows with the length of the texts times the number of differences, so two long files that are nearly the same compare almost instantly.

Reading the result

Where a block of lines changed, the removed lines come first and the added ones follow, in the same order diff -u prints them.

Ignoring whitespace

Tick Ignore whitespace when you've re-indented code, or when a stray trailing space clutters the result. Lines that differ only in spaces, tabs, or other whitespace then count as unchanged. Like diff -w, the option removes all whitespace before comparing, so a b and ab match too. Where lines match this way, the result shows the changed text's version.

The checker never compares line endings, so a file with Windows CRLF endings and the same file with Unix LF endings come out identical, whether the option is on or off.

Limits

On the command line

For files in a Git repository, use git diff, which compares against the history for you. The checker is for text that isn't in a repository, such as two versions of an email or a config snippet. To compare two files in a terminal:

diff -u original.txt changed.txt

-u prints the unified format, with + and - markers and three lines of context around each change. Add -w to ignore whitespace the way the checkbox does. Git can compare any two files, even outside a repository, with git diff --no-index original.txt changed.txt, and git diff --word-diff marks the changed words within each line, which the checker can't do.

More in text

Other tools