Text Diff Checker

Original
Changed
Result

What is a Text Diff?

A diff (short for "difference") is the result of comparing two pieces of text to identify what changed between them. The output highlights which lines were added, removed, or left unchanged. Diff tools are one of the most fundamental utilities in software development — they power code review, version control systems, configuration management, and document comparison.

The concept dates back to the original Unix diff command, written by Douglas McIlroy in 1974. Today, every developer interacts with diffs daily through Git, pull requests, and code review tools.

How Diff Algorithms Work

At its core, a diff algorithm solves the Longest Common Subsequence (LCS) problem. Given two sequences of lines, the algorithm finds the largest set of lines that appear in both texts in the same order. Everything that is not part of the LCS is a difference:

The classic LCS algorithm runs in O(mn) time, where m and n are the number of lines in each text. More advanced algorithms like Myers' diff algorithm (used by Git) optimize for the common case where most lines are identical, achieving near-linear performance on typical inputs.

Diff Formats: Unified vs. Side-by-Side

There are two standard ways to display differences:

This tool supports both views — switch between them using the toggle above the results.

Common Use Cases

  1. Code review: Reviewing diffs is the core activity in pull requests. Reviewers examine what lines were added, modified, or deleted to assess code quality and correctness.
  2. Configuration changes: Before deploying config changes (Nginx, Kubernetes YAML, environment variables), comparing the old and new versions catches unintended modifications.
  3. Document comparison: Comparing drafts of legal documents, specifications, or contracts to track what changed between revisions.
  4. Debugging: Comparing a working config or code snapshot against a broken one to isolate the change that introduced a bug.
  5. Database migrations: Reviewing SQL schema diffs before applying migrations to production.

How to Use This Tool

  1. Paste your original text in the left field and the changed text in the right field.
  2. Click Compare to generate the diff.
  3. Review the results — additions are highlighted in green, deletions in red, and unchanged lines are plain.
  4. Use the Unified / Side by Side toggle to switch between display modes.
  5. Click Swap to reverse the original and changed texts, or Clear to start over.

Everything runs in your browser — no text is uploaded to any server.

Frequently Asked Questions

What is a text diff?

A text diff is the result of comparing two pieces of text to identify their differences. The output highlights which lines were added, removed, or left unchanged. Diffs are fundamental to software development, used in code review, version control, and configuration management.

How does diff work?

Diff algorithms work by finding the Longest Common Subsequence (LCS) between two texts. The LCS represents the largest set of lines that appear in both texts in the same order. Everything not in the LCS is either an addition (present only in the new text) or a deletion (present only in the original text).

What do the colors mean in a diff?

Green (or lines prefixed with +) indicates additions — lines present in the changed text but not the original. Red (or lines prefixed with -) indicates deletions — lines present in the original but removed in the changed text. Unmarked lines are unchanged and provide context.

Can I compare files with this tool?

Yes. Copy and paste the contents of any two text files into the Original and Changed fields, then click Compare. The tool works with any plain text — code, configuration files, prose, CSV data, logs, and more.

What is a unified diff format?

A unified diff shows changes in a single interleaved view. Each line is prefixed with a space (unchanged), a plus sign (added), or a minus sign (removed). This is the default format used by git diff and most modern diff tools because it is compact and easy to read.

How is diff used in Git?

Git uses diff extensively: git diff shows uncommitted changes, git diff --staged shows staged changes, and pull requests display diffs of all commits in a branch. Git's diff engine compares file snapshots between commits and presents the differences in unified diff format.