Skip to content
AgileLogics

Code Difference Comparison Tool

Compares two blocks of text line-by-line using a longest-common-subsequence diff and shows which lines were added, removed, or unchanged.

How it works

Paste the original text in the input panel and the changed version in the second panel, then click Compare.

What is a code diff tool?

A code diff tool compares two versions of a text and shows what changed between them. This one works line by line: it finds the longest run of lines the two versions share, in order, and marks everything else as removed from the original or added in the changed version. It works for source code, config files, CSV rows, word lists or prose.

How to compare two texts

  1. Paste the older version into the Original box.
  2. Paste the newer version into the Changed box.
  3. Click Compare.

Every line from both versions appears in the output once, in order, with a two-character prefix:

Prefix Color Meaning
(two spaces) none The line is in both versions
- red The line is only in the original (removed)
+ green The line is only in the changed version (added)

If the two texts are identical, you get "No differences found." instead. An empty box counts as zero lines, so leaving Original empty lists every line of the changed version as +, and leaving Changed empty lists every original line as -.

Worked example

Original:

function greet(name) {
  console.log("Hello " + name);
  return true;
}

Changed:

function greet(name, greeting) {
  console.log(greeting + " " + name);
  return true;
}

Output:

- function greet(name) {
-   console.log("Hello " + name);
+ function greet(name, greeting) {
+   console.log(greeting + " " + name);
    return true;
  }

The first two lines changed, so their old versions are listed as removed and their new versions as added. The last two lines match and are shown with a leading space. When removals and additions sit at the same spot, the removals come first.

How the comparison works

The tool computes a longest common subsequence (LCS) of lines: the largest set of lines that appear in both texts in the same order. Those lines are "unchanged", and anything outside that set becomes a - or + line. Git's default diff algorithm, Myers' algorithm, solves the same problem more efficiently on large files (git diff documentation), so the results here usually match what you'd see in a code review, though ties can be broken differently.

A few consequences of comparing whole lines exactly:

  • Moved lines show as a removal plus an addition. If three moves from the end of a list to the top, the output shows + three at the top and - three at the bottom.
  • Whitespace and case count. a and a (trailing space) differ, and so do a and A.
  • Reformatting looks like a rewrite. Re-indenting a file changes almost every line, so the real edit gets lost among them.
  • No hunks. Unlike git diff or the unified format, the output shows the whole file rather than a few lines of context around each change, and there are no @@ line-number headers. It's meant for reading, not for applying as a patch.

Getting a cleaner diff

Most noisy diffs come from formatting rather than content. Normalize both sides the same way before comparing:

  1. For JSON, run both versions through the JSON formatter. Minified and pretty-printed copies of the same data then compare as identical, and only real value changes remain.
  2. For HTML, CSS or JavaScript, use the code beautifier on both sides so indentation and line breaks match.
  3. For lists where order doesn't matter, such as email lists or package names, sort both sides with the text sorter first. Then the diff shows only items that are genuinely missing or new.
  4. To see which lines a clean-up removed, paste your list before and after using Remove Duplicate Lines. Every dropped copy shows up as a - line.

Size limit

Comparing every line against every other line uses memory in proportion to the two line counts multiplied together, so the tool stops at 250,000 line pairs. Two 500-line files fit; two 501-line files don't, and neither do 1,000 lines against 300. For larger files, compare one function or section at a time, or use git diff --no-index old.txt new.txt on your own machine, which handles files of any size.

Last updated

Frequently asked questions

Does it highlight the exact words that changed within a line?
No. The comparison works on whole lines. If one character in a line changes, the old line is shown as removed (-) and the new line as added (+), one above the other, so you can spot the difference by reading the pair.
Why does a line that looks identical show as changed?
Lines are compared exactly, so a trailing space, a tab instead of spaces, or a change in capitalization makes them different. Paste both versions into a plain text editor that shows whitespace, or run both through the same formatter first.
How large can the two texts be?
The number of lines in the original multiplied by the number of lines in the changed text must be 250,000 or less, for example 500 lines each, or 1,000 against 250. Larger inputs show an error asking you to compare smaller sections.
Why does the diff end with an added blank line?
One version ends with a line break and the other doesn't. The text after the final line break counts as an empty last line, so it appears as + (or -) followed by nothing.
Is my code uploaded anywhere?
No. The comparison runs in JavaScript in your browser, so both versions stay on your device. That makes it safe for private code, config files and logs.