What is Diff? Complete Guide with Examples
Diff is a tool and output format that shows the differences between two files or text versions. Originally a Unix command-line utility, diff is now fundamental to version control systems (Git), code review platforms (GitHub, GitLab), and development workflows. The diff output shows which lines were added, removed, or modified between two versions, using a standardized format that both humans and tools can interpret.
Use our free tools to experiment with diff (code comparison).
How Does Diff (Code Comparison) Work?
Diff algorithms compute the minimum edit distance between two sequences of lines using dynamic programming approaches like the Myers algorithm. The result is an edit script describing the minimal set of insertions and deletions to transform one file into the other. Output formats include unified diff (showing context with +/- prefixes), side-by-side (two columns), and context diff (showing surrounding lines). Git extends basic diff with word-level highlighting, rename detection, and binary file handling.
Key Features
- Unified diff format showing changes with + (added) and - (removed) prefixes and context lines
- Side-by-side comparison mode for visual review of changes
- Word-level and character-level diff for identifying specific changes within lines
- Git integration for comparing commits, branches, staging area, and working tree changes
- Directory comparison (recursive diff) for finding differences across entire projects
Common Use Cases
Git Version Control
Every git commit stores diffs — the changes from the previous version. Commands like git diff, git log -p, and git show display diffs for reviewing changes, understanding history, and debugging regressions.
Pull Request Code Review
GitHub and GitLab present pull request changes as diffs, allowing reviewers to see exactly what code was added, removed, or modified in each file, with inline commenting for feedback.
Configuration Change Tracking
Operations teams compare configuration files between environments or versions to identify what changed, verify deployments, and troubleshoot issues caused by config modifications.