Text Diff Checker
Compare two texts, code files, or documents side by side. Highlights every added, removed, and unchanged line — instantly, in your browser.
Paste Your Texts to Compare
What Is a Text Diff?
A diff (short for "difference") is a comparison between two text inputs that highlights exactly what changed. The concept was invented in the early 1970s at Bell Labs as part of Unix development. Today, diff algorithms are the foundation of version control systems like Git, code review tools, and document comparison utilities. Lines prefixed with − were removed, lines with + were added, and unmarked lines are unchanged context.
How the Diff Algorithm Works
This tool uses the Longest Common Subsequence (LCS) algorithm — the same algorithm behind git diff, the Unix diff command, and most code review platforms. LCS finds the longest sequence of lines common to both texts (in order, but not necessarily contiguous), then marks everything else as added or removed. This produces a minimal diff — the smallest set of changes needed to transform text A into text B.
The algorithm has a time complexity of O(n × m) where n and m are the number of lines in each input. For very large files (thousands of lines), optimised algorithms like Myers' diff (used by Git) improve performance, but LCS is accurate and practical for typical comparisons.
Diff View Modes
| Mode | Description | Best For |
|---|---|---|
| Side-by-Side | Old and new text shown in parallel columns | Code review, seeing full context of both versions |
| Unified / Inline | Changes shown in a single column with + and − markers | Quick scanning, patch files, compact view |
| Word-level | Highlights individual word changes within lines | Document editing, catching small typos |
Common Use Cases
- Code review: See what changed between two versions of source code — function additions, bug fixes, refactors. This is the foundation of pull request reviews in GitHub, GitLab, and Bitbucket.
- Document comparison: Compare contract revisions, legal documents, or article drafts to catch every word change before signing or publishing.
- Configuration auditing: Compare server configs,
.envfiles,nginx.conf, or Kubernetes manifests to verify what changed during deployment. - API response debugging: Paste two JSON/XML API responses to spot differences — useful when an API behaves differently in staging vs production.
- Plagiarism and content analysis: Compare two documents to find shared text, useful for academic integrity checks.
- Database migration scripts: Compare SQL schema dumps to see what tables, columns, or indexes changed between versions.
Diff Options Explained
- Ignore whitespace: Treats differences in spaces, tabs, and trailing whitespace as equal. Useful when comparing code with different formatting (tabs vs spaces, trailing spaces). Prevents false positives from auto-formatters.
- Ignore case: Treats uppercase and lowercase letters as identical. Useful for comparing text where capitalisation doesn't matter — SQL keywords, configuration values, or non-case-sensitive identifiers.
Understanding Diff Output
The unified diff format (used in patches and version control) adds context around each change. A typical hunk header looks like @@ -12,7 +12,8 @@, meaning the change starts at line 12 in both files, showing 7 lines from the old file and 8 from the new. Lines starting with - exist only in the old version, + only in the new, and lines with no prefix are unchanged context shared by both.
Diff in Version Control
Git uses diff extensively. Key Git diff commands include:
git diff— shows unstaged changes in your working directorygit diff --staged— shows changes staged for the next commitgit diff branch1..branch2— compares two branchesgit diff HEAD~3— shows changes in the last 3 commitsgit diff --word-diff— shows word-level changes instead of line-level
Tips for Clean Diffs
- Consistent formatting: Use a code formatter (Prettier, Black, gofmt) so diffs only show meaningful changes, not whitespace adjustments.
- Small, focused commits: Each commit should address one concern. This makes diffs easier to review and understand.
- Sort imports and declarations: Alphabetically sorted imports produce smaller diffs when adding or removing items.
- Avoid unnecessary refactors: Don't rename variables or reformat code in the same commit as a bug fix — it obscures the actual change.
Frequently Asked Questions — Diff Checker
A diff (difference) shows the changes between two versions of text. This tool uses the Longest Common Subsequence (LCS) algorithm — the same used by git diff and Unix diff — to find the minimal set of additions and deletions needed to transform text A into text B. Lines only in A are marked as removed (red), lines only in B as added (green), and unchanged lines are shown as context.
Unified diff (used by git) shows additions prefixed with + and deletions with -, interleaved in a single view with context lines. Side-by-side diff (used here) shows the two versions in parallel columns, making it easier to visually compare corresponding sections. Side-by-side is better for human review; unified diff is better for patches and tooling.
Yes — paste any two code snippets to see exactly what changed. This is useful for reviewing code changes before committing, comparing config files, spotting accidental changes, or validating that a refactor didn't change behavior. For large files, copy-paste the relevant sections. All processing happens in your browser — no content is sent to any server.
On Unix/Linux/Mac: diff file1.txt file2.txt (basic), or diff -u file1.txt file2.txt (unified format). For side-by-side: diff -y file1.txt file2.txt. For recursive directory comparison: diff -r dir1/ dir2/. In Git: git diff HEAD~1 HEAD shows changes since the last commit. git diff --stat gives a summary of changed files.
Most Unix tools expect text files to end with a newline character (\n). When a file is missing this final newline, diff tools add a warning "\ No newline at end of file." This is cosmetic but can cause issues with certain tools and violates POSIX. In git, this appears as a diff change even if the file content is otherwise identical, which can cause confusing diffs.