Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path
Diff Checker
A text diff checker. Paste an original and a changed version to see a line-by-line comparison — additions, removals and unchanged lines highlighted — computed with a longest-common-subsequence diff, entirely in your browser. Handy for comparing configs, logs, JSON, or any two versions of text.
Finding what changed between two texts is not as simple as comparing line one to line one. Insert a single line at the top and a naive comparison reports every following line as changed. This checker anchors on the lines both versions share, in order, and reports only what falls outside them.
What it computes
Both inputs are split into lines at each newline. The tool then fills a table of longest-common-subsequence lengths, where each cell answers how many lines the rest of the original and the rest of the changed text have in common:
L[i][j] = 0 past the end of either text
= L[i+1][j+1] + 1 if a[i] equals b[j]
= max(L[i+1][j], L[i][j+1]) otherwise
It then walks both texts from the top. Equal lines are output as unchanged and both sides advance. Otherwise it drops the original’s line as a removal if doing so keeps the longest common run, and takes the changed text’s line as an addition if not; on a tie it removes first, so a removal is listed before the addition that replaces it. Leftover lines at the end are removals or additions. The bar above the output counts each kind.
The table has one cell per pair of lines, so for very large inputs, more than 4 million pairs such as two files of over 2,000 lines each, the tool falls back to marking every original line removed and every changed line added.
A worked example
The defaults compare a three-line original with a four-line changed version:
| Original | Changed |
|---|---|
const port = 3000; | const port = 8080; |
const host = "localhost"; | const host = "localhost"; |
start(host, port); | const tls = true; |
start(host, port); |
The longest common subsequence is two lines long: the host line and the start line. Everything else is an edit, and the output reads:
- const port = 3000;
+ const port = 8080;
const host = "localhost";
+ const tls = true;
start(host, port);
The counters show +2 and −1. The changed port is one removal plus one addition, because the tool compares whole lines, and the new tls line is a pure addition slotted between two unchanged lines. Press Swap and the same comparison runs in reverse: +1 and −2.
Trade-offs and limits
- Exact matching. Case, spaces, tabs and invisible characters all count. A trailing space or a non-breaking space makes two lines different. Windows line endings do not, because the text box converts them to plain newlines before the comparison runs.
- No inline highlighting. An edited line is shown as removed and re-added; the changed characters inside it are not marked.
- No move detection. A block moved elsewhere appears as a removal in one place and an addition in another.
- Quadratic cost. Time and memory grow with the product of the two line counts, which is why very large inputs get the coarse fallback.
- Ties are resolved one way. When several minimal diffs exist, the tool always prefers removing first, so it can group edits differently from other tools.
The counts follow from the subsequence alone. With n original lines, m changed lines and a common subsequence of length k, the tool always reports n − k removals and m − k additions. The default has k = 2, so 3 − 2 = 1 removal and 4 − 2 = 2 additions. No line-level diff can report fewer; what each tool can change is which lines it pairs up.
| Ignored here | What you see instead | Where to get it |
|---|---|---|
| Changes inside a line | One edited character costs a − line and a + line | git diff --word-diff |
| Moved blocks | A 30-line function moved down the file shows as 30 removals and 30 additions | git diff --color-moved |
| Whitespace-only edits | Every re-indented line is a change | git diff -w |
| Very large inputs | Past 4,000,000 line pairs, every line is removed and re-added | Git, or split the file |
How to use the result
- Normalize first. Format both sides the same way, sort JSON keys and strip trailing whitespace, so the diff shows meaning rather than formatting.
- Read pairs as edits. A removal directly followed by an addition is usually one changed line; compare the two by eye to spot the exact characters.
- Check the counts. A large count on a small change usually means a whitespace mismatch, such as re-indented lines or trailing spaces, not real edits.
- Diff config before deploying. Comparing the current and proposed file is a quick review that catches stray edits.
When to use it, and when not
Use it for short texts you have in hand but not in version control: a config copied from two servers, an API response from before and after a deploy, the same log line from staging and production, a snippet a colleague pasted into chat. There is no repository to set up and nothing to install.
Reach for something else when the files already live in git, where git diff knows the history and has whitespace and move options this tool lacks. Skip it when either side runs to thousands of lines: at 2,500 lines against 1,700 the product is 4,250,000 pairs, past the guard, and the output marks all 4,200 lines as changed. Prose suits a word-level diff, where one edited word does not cost a whole line. For JSON, use the JSON diff tool, which sorts keys first so reordering stops looking like an edit.
Common mistakes
- A trailing newline on one side only.
a,bagainst the same two lines plus a final newline shows +1: the split produces an empty last line, and it is reported as an added blank line. - Counting lines as edits. The default shows +2 and −1, three lines, but only two edits were made: the port changed and the
tlsline was added. A − line directly above a + line is usually one edit. - Diffing before formatting. If one side went through a formatter and the other did not, re-indented lines all differ. Run both through the same formatter first, or the real change is buried.
- Comparing order-free config by line.
port: 80,host: aagainst the same two lines swapped shows −1 and +1, though the settings are identical. Sort the lines first, or for JSON use the JSON diff tool. - Treating a whole-file rewrite as proof of big changes. If the counters equal both line counts, check whether the 4,000,000-pair fallback kicked in or whether every line gained a trailing space before reading anything into it.
Check yourself
Original a b c d, one per line; changed a c d b. What does the tool show?
The longest common subsequence is a c d, length 3, so there is 4 − 3 = 1 removal and 4 − 3 = 1 addition: −b after a, then +b at the end. A moved line is always a removal plus an addition here.
The original has 40 lines, the changed text 46, and the counter shows +9. How many removals, and how long is the common subsequence?
Additions are m − k, so k = 46 − 9 = 37 lines in common. Removals are n − k = 40 − 37 = 3. The two counters always differ by exactly m − n, here 6.
A 2,500-line file against a 1,500-line version of it. Full diff or fallback?
Full diff: 2,500 × 1,500 = 3,750,000 pairs, under the 4,000,000 limit. If the shorter file were the first 1,500 lines of the longer one, the result would be −1,000 and +0. At 1,700 lines the product is 4,250,000 and every line would be marked changed.
Original x, changed y. Why is the removal listed before the addition?
Neither line matches, so the common subsequence is empty either way. Skipping x and skipping y both leave a run of 0, and on a tie the tool removes first. A tool that preferred additions would list +y first with the same counts.
n − k and m − k.How it works
- Line-by-line comparison via a longest-common-subsequence diff.
- Additions, removals and unchanged lines marked, with + and − counts.
- Finds a minimal set of line edits, the same goal git’s diff has.
- Runs entirely in your browser; nothing is uploaded.
Frequently asked questions
How does the diff decide what changed?
It computes the longest common subsequence of the two texts, line by line: the longest sequence of lines that appears in both versions in the same order. Lines in that sequence are shown as unchanged, lines found only in the original are removals, and lines found only in the changed version are additions. Anchoring on the common lines is what stops one inserted line at the top from making every later line look different, which is what a naive line-1-to-line-1 comparison would report.
Is this the same algorithm git uses?
It solves the same problem but not in the same way. Finding the longest common subsequence is equivalent to finding the smallest set of line insertions and deletions, which is what git’s default Myers algorithm also finds, only much faster on large files. When several equally small edit scripts exist, tools can choose differently, so this checker and git may group a change slightly differently while usually counting the same number of added and removed lines. Git’s default also takes shortcuts on large, heavily edited files that can report a slightly larger diff; git diff --minimal turns them off.
Is my text sent anywhere?
No. Both inputs are compared entirely in your browser with JavaScript; nothing is uploaded, logged or stored by the tool. That makes it reasonable to diff configuration files, logs or other sensitive text, though you should still follow your organization’s rules for handling secrets. When you close or reload the page, the text is gone, because the inputs are not saved anywhere, including your browser’s storage.
Does it diff word by word or line by line?
Line by line. That is the right granularity for code, configuration, logs and structured data, where a change usually means a whole line was added, removed or edited. An edited line shows as one removal followed by one addition, without highlighting the changed characters inside it. Word-level or character-level diffing suits prose better, but it gets noisy on code, where a renamed variable would otherwise light up dozens of fragments.
Why does it show differences in lines that look identical?
Because the comparison is exact. A trailing space, a tab instead of spaces, a different quote character or a non-breaking space all make two lines unequal even when they look the same on screen. Line endings are the one thing that cannot cause it here: a browser text box turns Windows carriage-return line endings into plain newlines, so a file pasted from Windows matches the same file from Linux. Command-line tools such as diff do not, and there a Windows file can differ on every line. Normalize whitespace on both sides before comparing if only content matters.
Can I compare JSON or formatted data?
Yes. Paste both versions and it diffs them line by line. For the cleanest result, format both sides the same way first, with consistent indentation and key order, so only real value changes show up rather than formatting noise. Two pretty-printed JSON documents with sorted keys put each field on its own line, which turns the diff into an exact list of the fields that were added, removed or changed.