Text Diff Checker - Compare Two Texts Online
Compare two blocks of text side by side and see differences highlighted. Identify additions, deletions, and modifications instantly.
How Diff Works
A diff algorithm compares two texts and produces the shortest sequence of edits — insertions and deletions — needed to transform one into the other. The most widely used algorithm is Myers diff (published 1986), which powers Git, GitHub, and most modern diff tools.
Standard diff output uses a unified format:
- Lines starting with
+are additions (in the new version) - Lines starting with
-are deletions (from the old version) - Lines starting with a space are context (unchanged)
Common Use Cases
- Code review: Compare a function before and after refactoring to verify that logic was not accidentally changed.
- Configuration auditing: Diff config files between environments (dev vs. production) to find unauthorized or unexpected differences.
- API response comparison: Paste the JSON responses from two API versions side by side to spot breaking changes.
- Document proofreading: Identify what changed between two drafts of a document or legal agreement.
- Database query output: Compare query results before and after an index change or schema migration.
- Merge conflict resolution: Understand exactly what two branches changed about the same section of code.
Diff in the Terminal
Unix diff command
# Basic line diff
diff original.txt modified.txt
# Unified format (what Git uses)
diff -u original.txt modified.txt
# Side-by-side comparison
diff -y original.txt modified.txt
# Ignore whitespace
diff -w original.txt modified.txt Git diff
# Show unstaged changes
git diff
# Compare two branches
git diff main..feature-branch
# Compare specific files between commits
git diff HEAD~1 HEAD -- path/to/file.ts
# Word-level diff (highlight changed words, not lines)
git diff --word-diff Reading a Diff — Example
@@ -1,5 +1,6 @@
function greet(name) {
- return "Hello " + name;
+ return `Hello, ${name}!`;
+ // Updated to use template literals
} The @@ line shows the position: lines 1–5 in the original (-1,5), lines 1–6 in the new version (+1,6). The red line was removed, the two green lines were added.
Tips for Effective Diffing
- Normalize whitespace and line endings before diffing to avoid noise from formatting-only changes.
- Use semantic diff tools (e.g.,
ast-difffor code) when structural changes matter more than textual ones. - For large files, focus on changed sections — most diff tools support folding unchanged context.
- When comparing JSON or YAML, format/sort keys first so structural differences are not obscured by key ordering.
Frequently Asked Questions
What is a diff and how does it work?
A diff shows what changed between two versions of text. The Myers algorithm finds the shortest edit script — the minimum insertions and deletions to transform one text into the other. Added lines appear in green, removed lines in red. Unchanged lines are shown as context.
What are common uses for a text diff tool?
Diff tools are used for: comparing code before and after a change, reviewing config file differences between environments, verifying refactoring produced no unintended changes, comparing API responses, and spotting differences between two versions of any document.
What is the difference between line diff and character diff?
Line diff compares entire lines — a changed line shows as a deletion and addition pair. Character (inline) diff highlights the exact characters that changed within a modified line, making it easier to spot small typos or single-value changes in long lines.