How the Text Diff works

The tool compares the two texts line by line with the Myers diff algorithm, the same approach used by git diff and GNU diff. It finds the smallest set of added and removed lines that turns the original into the changed text, so moved or edited lines are matched up with as little noise as possible. Each side can have up to 20,000 lines; for texts that are completely different, the comparison stops after a few seconds and shows the differing part as replaced rather than freezing the page.

When a removed line is followed by an added line, the pair is shown as a change and compared again word by word, so you can see exactly which words, numbers or punctuation marks changed. Ignore case treats upper and lower case as equal, and Ignore whitespace ignores all spaces and tabs, like diff -w. Unchanged lines more than three lines away from a change are folded unless you tick Show all unchanged lines.

The unified diff at the bottom uses the standard format with --- and +++ headers and @ hunks with three lines of context, so you can paste it into a code review, an issue or a patch tool. If the last line of a text has no line break after it and appears in a hunk, the line \ No newline at end of file is added, as diff does.

How to use the Text Diff

  1. Paste the original text into the Original text box and the new version into the Changed text box, or open a file for each. Select Load example to try it.
  2. Choose the View (Side by side or Inline) and, if needed, tick Ignore case, Ignore whitespace or Show all unchanged lines.
  3. Select Compare or press Ctrl + Enter. Added lines are shown in green, removed lines in red, and the words that changed inside a line are highlighted.
  4. Copy the unified diff or download it as a .diff file to share the changes.

Example

Comparing the original:

host = localhost
port = 8080
debug = true

with the changed text:

host = localhost
port = 9090
debug = false
timeout = 30

reports 3 added, 2 removed and 1 unchanged line, highlights 80809090 and truefalse inside the changed lines, and produces this unified diff:

--- original
+++ changed
@@ -1,3 +1,4 @@
 host = localhost
-port = 8080
-debug = true
+port = 9090
+debug = false
+timeout = 30

Common use cases

  • Reviewing what an editor or colleague changed in a document or contract.
  • Comparing two versions of a configuration file before a deployment.
  • Checking the differences between two SQL queries, API responses or code snippets.
  • Creating a unified diff to paste into a bug report or code review.

Frequently asked questions

How does the comparison work?

The texts are compared line by line with the Myers diff algorithm, which finds the smallest number of added and removed lines, the same approach used by git diff. When a removed line is directly replaced by an added line, the two are compared again word by word so only the words that changed are highlighted.

What do Ignore case and Ignore whitespace do?

Ignore case treats upper and lower case letters as the same. Ignore whitespace ignores all spaces and tabs within lines, like diff -w, so re-indented or re-spaced lines are not reported as changed. It also ignores a missing line break at the end of the text.

How large can the texts be?

Each text can have up to 20,000 lines. Texts that are mostly similar compare in well under a second. If two large texts are almost completely different, the comparison stops after a few seconds and shows the remaining part as replaced, so the page does not freeze. The on-screen view shows up to 5,000 rows; the unified diff always contains every change.

What is a unified diff?

It is the standard text format for changes used by git, patch and code review tools. Lines starting with - were removed, lines starting with + were added, and lines starting with a space are unchanged context. Each group of changes starts with an @@ line giving the line numbers in both versions.

Why is the last line shown as changed when it looks the same?

One text ends with a line break and the other does not. The view notes this next to the line, and the unified diff adds "\ No newline at end of file" as diff does. Tick Ignore whitespace to ignore the difference.

Are my texts uploaded?

No. The comparison runs in your browser and neither text is sent to our server.