Diff Checker
Compare two texts and visualize the differences. See additions, deletions, and unchanged lines.
You May Also Like
What is a Diff?
A diff (short for "difference") shows the changes between two versions of text. It highlights what was added, removed, or modified - like a track changes feature for any text.
Why diffs matter:
- Code review: See exactly what changed in a pull request
- Debugging: Find what broke between versions
- Documentation: Track content changes over time
- Collaboration: Merge work from multiple people
The diff format was invented in the 1970s for Unix and is still the foundation of modern version control systems like Git.
Types of Diff Views
1. Unified Diff (Most Common)
@@ -1,4 +1,4 @@
function greet(name) {
- return "Hello, " + name;
+ return `Hello, ${name}!`;
}
- Lines starting with
-were removed - Lines starting with
+were added - Context lines (unchanged) have no prefix
2. Side-by-Side
Old New
──────────────────── ────────────────────
function greet(name) { function greet(name) {
return "Hello, " + return `Hello,
name; ${name}!`;
} }
Easier to compare visually, but uses more space.
3. Inline/Word Diff
return "Hello, " + name;[- → return `Hello, ${name}!`;+]
Highlights changes within lines.
How to Read a Diff
The Header
--- a/file.txt
+++ b/file.txt
@@ -10,7 +10,8 @@
---= old file+++= new file@@ -10,7 +10,8 @@= location info- Starting at line 10, showing 7 lines (old)
- Starting at line 10, showing 8 lines (new)
The Content
unchanged line
-removed line
+added line
another unchanged line
Pro tip: The space before unchanged lines is intentional! It preserves alignment and makes diffs parseable.
Diff Algorithms
Different algorithms produce different results:
Myers Algorithm (Default in Git)
- Finds minimum edit distance
- Good balance of speed and quality
- Most widely used
Patience Diff
- Better for code with moved blocks
- Handles function reordering well
git diff --patience
Histogram Diff
- Optimized patience algorithm
- Default in Git since 2.35
git diff --histogram
Word-level Diff
- Compares words instead of lines
- Great for prose and documentation
- Shows inline changes
| Algorithm | Best For | Trade-off |
|---|---|---|
| Myers | General use | Fast, may miss moves |
| Patience | Code restructuring | Slower, clearer output |
| Histogram | Large files | Balanced |
| Word | Documentation | More detailed |
Practical Uses
🔍 Code Review
git diff main feature-branch
See all changes before merging.
📜 File Comparison
diff file1.txt file2.txt
Compare any two text files.
⏪ Finding Bugs
git bisect + git diff
Find which commit introduced a bug.
📝 Configuration Changes Compare server configs to find differences:
diff /etc/nginx/nginx.conf nginx.conf.backup
🔄 Merge Conflicts When Git shows:
<<<<<<< HEAD
your changes
=======
their changes
>>>>>>> branch
Use diff to understand what conflicted.
Tips for Better Diffs
✅ Making Diffs Readable:
-
Make small, focused commits
- Easier to review
- Easier to revert if needed
-
Separate refactoring from features
- Formatting changes hide real changes
- Do reformatting in separate commits
-
Write meaningful commit messages
- Explains why, not just what
- Future you will thank present you
❌ Common Pitfalls:
- Whitespace noise: Use
diff -wto ignore - Line ending issues:
\r\nvs\n - Binary files: Diff can't handle images, PDFs
- Large diffs: Break into smaller changes
Git tip: Configure git diff --color-words for better prose diffs. It highlights word-level changes instead of whole lines.
Popular Diff Tools
Command Line:
diff- Unix standardgit diff- Git's built-incolordiff- Colorized output
GUI Tools:
| Tool | Platform | Notable Feature |
|---|---|---|
| VS Code | All | Built-in, excellent |
| Beyond Compare | All | Three-way merge |
| Meld | Linux/Windows | Visual merging |
| Kaleidoscope | macOS | Beautiful UI |
| WinMerge | Windows | Free, powerful |
Online:
- This tool! Perfect for quick comparisons
- GitHub/GitLab diff view
- Diffchecker.com