🔍 Text Diff
Paste two texts and compare them line by line.
What Is Text Diff and How Does It Work?
Text diff, short for "difference," is the process of comparing two versions of a text to identify what has been added, removed, or changed between them. The concept originated in the Unix world with the diff utility created in the early 1970s, and it remains one of the most important tools in software development, content editing, and data analysis. At its core, a diff algorithm compares two sequences line by line and produces a minimal set of changes that would transform one text into the other.
How Diff Algorithms Work
Most diff tools use a variant of the Longest Common Subsequence (LCS) algorithm. This algorithm finds the longest sequence of lines that appear in both texts in the same order, then treats everything else as either an insertion or a deletion. The result is displayed with color coding: green lines with a "+" prefix indicate additions, red lines with a "-" prefix indicate deletions, and unchanged lines provide context. More advanced tools use the Myers diff algorithm, which finds the shortest edit script and is the algorithm behind Git's built-in diff.
Common Use Cases
Code review is the most well-known use case. Developers on platforms like GitHub and GitLab review pull requests by reading diffs to understand exactly what changed. Document comparison is equally valuable for legal professionals comparing contract drafts, editors tracking changes across article revisions, and students verifying corrections in academic papers. Configuration management teams use diff to audit changes to server configurations and catch unintended modifications before they cause outages.
Beyond Plain Text
While this tool compares plain text line by line, specialized diff tools exist for structured data formats. JSON diff tools compare nested objects and arrays, XML diff handles hierarchical document trees, and semantic diff tools for programming languages understand syntax, so they can ignore insignificant whitespace while highlighting meaningful code changes. Regardless of the format, the underlying principle is the same: show exactly what changed between two versions so you can review, merge, or revert with confidence.