Skip to main content

Compare two text blocks and see differences.

+3 added-2 removed
-function greet(name) {
+function greet(name, greeting = "Hello") {
- console.log("Hello " + name);
+ console.log(greeting + " " + name);
}
greet("World");
+greet("Alice", "Hi");
All calculations performed locally in your browser. No data sent to server.

Results are for informational purposes. Verify results with other sources.

How text diffing works

A diff finds the smallest set of insertions and deletions that turns one text into another. It does not detect that a line 'moved' or 'changed' — those are interpretations a viewer layers on top of a delete followed by an insert.

How it works

  • Computes the longest common subsequence of the two inputs, then reports everything outside it as added or removed.
  • Works line by line by default, which is what makes diffs readable for code and useless for reflowed prose.
  • Marks a modified line as one deletion plus one insertion, because that is what it actually is at the algorithm level.
longest common subsequence (LCS)
  lines only in the left  → deletions
  lines only in the right → insertions
  lines in the LCS        → unchanged

similarity ≈ 2 × LCS length / (left lines + right lines)

Worked example

A three-line file with one line edited and one added.

  1. left: alpha / beta / gamma
  2. right: alpha / BETA / gamma / delta
  3. LCS = alpha, gamma (2 lines)
  4. beta → deletion, BETA → insertion, delta → insertion

Three changes reported, not two: the edit to beta counts as a delete plus an insert. Similarity = 2 × 2 / (3 + 4) = 57%.

Reading the result

  • A whole paragraph reflowed to a different line width produces a diff where every line changed, even though barely a word did. Switch to a word-level diff for prose, or diff the source before wrapping.
  • Trailing whitespace and line-ending differences produce phantom changes. If an entire file appears modified with no visible difference, check for CRLF versus LF first.
  • Diff output depends on which side you call 'original'. Swapping the inputs turns every insertion into a deletion, which matters when you are reading a review.
  • This runs in your browser, so pasting a confidential file here does not upload it. That is not true of every online diff tool.

Common questions

Why does my diff show the whole file as changed?
Almost always line endings or indentation. A file saved on Windows and edited on Linux differs on every single line invisibly. Enable whitespace-insensitive comparison, or normalise line endings first.
Can it show that I moved a block of code?
Not directly — a move is a deletion in one place and an insertion in another, and standard diff reports it as such. Some tools detect moves as a post-processing step over that raw output.