What is a Diff?
A diff (difference) shows the changes between two versions of text. It's a fundamental tool in software development, used for code review, version control, and document comparison. Diffs help developers understand what changed between versions, making collaboration and debugging much easier.
The term "diff" comes from the Unix diff command, which compares files line by line. Modern diff tools show additions, deletions, and context to make changes clear and actionable.
How to Use This Diff Checker
Basic Comparison:
- Paste your original text in the left panel
- Paste the modified text in the right panel
- Click "Compare" to generate the diff
- Review the highlighted changes below
Understanding the Output:
- Green (+): Lines added in the new version
- Red (-): Lines removed from the original
- Gray/Context: Unchanged lines showing surrounding context
- Line Numbers: Reference points for locating changes
Common Use Cases
- Code Review: Review changes before merging pull requests or commits
- Version Control: Understand what changed between file versions
- Documentation: Compare document versions to track changes over time
- Configuration Files: Identify differences in config files between environments
- Debugging: Compare expected vs actual output to find discrepancies
Types of Diff Output
Unified Diff
Shows changes in a compact format with context lines. Used by Git and most version control systems. Lines starting with + are additions, - are deletions, space are context.
Side-by-Side
Shows original and modified text in parallel columns. Easier to read for small changes but takes more space. This tool shows a visual side-by-side comparison.
Context Diff
Similar to unified but uses different markers (*** and ---) to separate file sections. Less common but still used in some legacy systems.
Diff Algorithms
Different algorithms produce different diff outputs. This tool uses a line-based comparison that works well for most text:
Myers Algorithm
Efficient algorithm that finds the minimum number of changes. Used by Git and most modern tools.
Longest Common Subsequence
Finds the longest sequence of unchanged lines, then shows differences around them.
Frequently Asked Questions
Q: Why do diffs show context lines?
Context lines help you understand where changes occurred. Without context, it would be hard to know which part of a large file was modified. Most diffs show 3-5 lines of unchanged context around each change.
Q: Can I diff binary files?
This tool is designed for text files. Binary files (images, executables) can't be meaningfully diffed line by line. Use specialized binary diff tools for those file types.
Q: What's the difference between diff and patch?
A diff shows the differences between files. A patch is a diff formatted in a way that can be applied to recreate the changes. The patch command can apply diff output to files.
Q: Why are some lines marked as changed when they look the same?
This usually happens when whitespace changed (spaces vs tabs, trailing spaces) or when the diff algorithm detects a more complex change pattern. Check for invisible characters.
Command Line Diff Tools
For power users, command-line diff tools offer more options:
Git Diff
git diff file1.txt file2.txt git diff --word-diff # Show word-level changes git diff --stat # Show summary statistics
Unix Diff
diff -u file1.txt file2.txt # Unified format diff -c file1.txt file2.txt # Context format diff -y file1.txt file2.txt # Side by side
Related Tools
- JSON Formatter - Format and compare JSON structures
- Regex Tester - Test patterns for text matching
- URL Encoder - Encode URLs for comparison