Diff
Ready to try Diff?
Access the free online tool now - no registration required
Diff - Complete Guide
Text diff compares two pieces of text and highlights the differences between them. This is essential for code review, tracking changes, debugging, and version comparison. The diff shows exactly what was added, removed, or modified between two versions.
How It Works
Diff algorithms find the longest common subsequence between texts, then mark non-matching sections as additions or deletions. Line-by-line diff is most common for code. Character-level diff shows changes within lines. Output formats include unified diff, side-by-side, and inline highlighting.
Technical Details
The Myers diff algorithm (used by git) finds the minimum edit distance efficiently. Unified diff format shows context lines around changes, with - for deletions and + for additions. Three-way diff compares against a common ancestor for merge conflict resolution.
Common Use Cases
- Code Review: Review changes between code versions.
- Example:
Compare function before and after refactoring
- Example:
- Configuration Comparison: Find differences between config files across environments.
- Content Editing: Track changes in documents and articles.
- Debugging: Compare expected vs actual output.
Code Examples
Command Line Diff
# Basic diff
diff file1.txt file2.txt
# Unified format (like git)
diff -u file1.txt file2.txt
# Ignore whitespace
diff -w file1.txt file2.txt
# Side by side
diff -y file1.txt file2.txt
# Git diff
git diff HEAD~1 -- file.js
Unix diff command is the standard tool. -u gives unified format, -y shows side by side.
Tips & Best Practices
- Use unified diff format for patches and code review
- Enable syntax highlighting in diff viewers for code
- Ignore whitespace when comparing reformatted code
- Use three-way diff for merge conflict resolution
Common Mistakes to Avoid
- Comparing files with different line endings (CRLF vs LF)
- Not using context lines in patches
- Ignoring whitespace when it matters (Python, YAML)
When to Use This Tool
Use diff when comparing any two versions of text: code changes, configuration differences, document revisions, or debugging output differences.
Frequently Asked Questions
What's the difference between line and word diff?
Line diff compares whole lines - any change marks the entire line as modified. Word/character diff shows exactly which words or characters changed within a line. Use line diff for code, word diff for prose.
How do I ignore whitespace changes?
Most diff tools have options: -w ignores all whitespace, -b ignores whitespace amount changes. Useful when comparing code with different formatting but same logic.
What's unified diff format?
Unified diff shows changes with context: lines starting with - are removed, + are added, space is unchanged context. Headers show file names and line numbers. This is the format used by git diff and patches.
Get Started
Ready to try Diff? Use the tool now - it's free, fast, and works right in your browser.
Last updated: June 27, 2026
Start using Diff
Free, fast, and privacy-focused - try it now
Share this article
Related Tools
Js Obfuscator
Js Obfuscator for clean, optimized code. Improve readability, reduce file size, or format your code professionally. Essential developer tool.
SQL Formatter
SQL Formatter for clean, optimized code. Improve readability, reduce file size, or format your code professionally. Essential developer tool.