What is a Diff?
A "diff" (short for difference) is a way to compare two versions of a text and see exactly what changed. It was originally a Unix command (diff file1.txt file2.txt) used by programmers to review code changes. Today, diff tools are built into every code editor, version control system, and many online tools.
How Diff Algorithms Work
Most diff tools use the Longest Common Subsequence (LCS) algorithm. It finds the longest sequence of lines that appear in both texts in the same order. Everything NOT in the LCS is considered added or removed.
The three line types in a diff:
| Symbol | Color | Meaning |
|---|---|---|
+ | Green | Line was added in the new version |
− | Red | Line was removed from the old version |
| Gray | Line is identical in both versions (context) |
Unified vs Split View
Unified view
Shows a single column with added and removed lines interleaved. More compact — you see the full context in one view. Standard in Git (git diff).
Split view
Shows the old version on the left and new version on the right, side by side. Better for understanding how a block of code changed.
Common Use Cases
- Code review — See what changed in a pull request
- Document comparison — Find changes between two contract drafts
- Config file comparison — Spot differences between dev and prod configs
- Log analysis — Compare log files from different runs
- Translation review — Find updated text in localization files
Git Diff: The Most Common Diff Tool
In Git, the git diff command shows changes between:
# Working directory vs staged changes
git diff
# Staged changes vs last commit
git diff --staged
# Two branches
git diff main feature/login
# Two files
git diff file1.txt file2.txt
Tips for Reading Diffs
- Focus on the red and green — unchanged context lines (gray) just provide orientation
- Look for patterns — a red/green pair next to each other usually means a line was modified
- Count the changes — a good code review has a manageable number of changed lines
- Check line numbers — helps you navigate to the right place in the original file
Compare any two texts instantly in your browser with our free Text Diff Checker — supports unified and split view with line numbers.