Text Diff Explained: How Line Diffing Works and When to Trust It
From LCS to character highlighting: how diff tools align two texts, what ignore-options actually compare, and a workflow for reviewing changes without git.
Every code review leans on a diff, yet the algorithm behind those red and green lines stays a mystery to most. It is one elegant idea — and knowing it helps you read imperfect diffs correctly.
The longest common subsequence
A diff splits both texts into lines and finds the longest common subsequence — the biggest chain of identical lines that appear in the same order. Everything else is marked added or removed. That is why moved paragraphs can show as delete-plus-add instead of a move: pure LCS does not model motion.
Line diff, then character polish
Line-level diffing stays fast even for thousands of lines. Good tools add a second pass: inside changed line pairs, highlight the exact character or word that changed. The Text Diff Checker shows both — block alignment plus character detail — entirely in your browser.
Formatting noise vs real changes
Indentation differences, capitalization and line-ending styles (CRLF vs LF) bury real edits. That is what the ignore-whitespace and ignore-case options exist for: they change what equality means before the LCS runs, so the diff reports content changes, not formatting churn.
Workflow beyond git
- Compare JSON responses before and after an API change — run both through the JSON Formatter first, then the diff aligns semantically instead of by incidental formatting.
- Review config or policy files copied between environments.
- Clean repeated lines in the inputs first with the Deduplicator so the diff reports real edits, not duplicates.
Because comparison is local, confidential documents and credentials are safe to run through the diff tool — nothing uploads anywhere.
Related guides
Why Your JSON Is Invalid: The 9 Most Common Syntax Errors
Trailing commas, unquoted keys, smart quotes and friends: the nine JSON syntax mistakes that break parsers, with instant fixes and a validation shortcut.
Read guide →2026-10-02JSON vs YAML vs XML: Choosing the Right Config Format
JSON, YAML and XML compared for configuration and data exchange: readability, schema support, editor safety and where each format still wins today.
Read guide →2026-10-12Base64 vs Hex Encoding: When to Use Each (Developer Guide)
Base64 vs hex encoding compared: size overhead, readability, common use cases in JWTs, data URLs and git diffs — with a quick decision table for engineers.
Read guide →Try these tools
Text Diff Checker
Compare two texts and see added, removed and unchanged lines with an LCS diff algorithm. Colors, counters and a line-by-line unified view — computed locally.
Open tool →Text Deduplicator
Remove duplicate lines from any list with options for trimming whitespace, ignoring case and dropping empty lines. Shows before/after counts and what was removed.
Open tool →JSON Formatter
Pretty-print JSON with 2/4-space or tab indentation, optional key sorting, and precise error positions when the JSON is broken. Private, instant, browser-only.
Open tool →