tallge

Tools / Diff checker

Text diff checker with unified diff output

Paste the original text into the first field and the changed text into the second. The result is a minimal line diff, shown with line numbers and as a unified diff.

How it works

The comparison uses the Myers algorithm, the same family of algorithm as git diff and GNU diff. It finds a shortest edit script: the smallest number of whole lines to delete and insert to turn the original into the changed text. When several shortest scripts exist, it may pick a different one than diff does, but never a longer one.

The unified output uses the diff -u format with three lines of context. Hunk headers such as @@ -2,3 +2,4 @@ give the first line and the line count on each side. A file that does not end with a newline gets the line \ No newline at end of file, as in GNU diff. Saved to a file, the output can be applied with patch original.txt < changes.diff. For the sample texts above it reads:

--- original
+++ changed
@@ -1,7 +1,7 @@
-function total(items) {
+function total(items, taxRate) {
   let sum = 0;
   for (const item of items) {
-    sum += item.price;
+    sum += item.price * item.quantity;
   }
-  return sum;
+  return sum * (1 + taxRate);
 }

Pitfalls

"Ignore whitespace differences" treats runs of spaces and tabs as one space and ignores leading and trailing whitespace. That is close to diff -b, which, unlike this tool, still notices indentation added at the start of a line. The displayed lines are still the original text. Line endings (LF, CRLF or CR) are never counted as differences.

The diff is line-based. A one-character change shows as a whole line removed and added. Very large inputs are refused: at most 20,000 lines per side and 4,000 changed lines, so the page stays responsive.