CalquioCalquio

Search

Search for calculators and tools

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
AlgorithmBest ForTrade-off
MyersGeneral useFast, may miss moves
PatienceCode restructuringSlower, clearer output
HistogramLarge filesBalanced
WordDocumentationMore 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:

  1. Make small, focused commits

    • Easier to review
    • Easier to revert if needed
  2. Separate refactoring from features

    • Formatting changes hide real changes
    • Do reformatting in separate commits
  3. Write meaningful commit messages

    • Explains why, not just what
    • Future you will thank present you

❌ Common Pitfalls:

  • Whitespace noise: Use diff -w to ignore
  • Line ending issues: \r\n vs \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 standard
  • git diff - Git's built-in
  • colordiff - Colorized output

GUI Tools:

ToolPlatformNotable Feature
VS CodeAllBuilt-in, excellent
Beyond CompareAllThree-way merge
MeldLinux/WindowsVisual merging
KaleidoscopemacOSBeautiful UI
WinMergeWindowsFree, powerful

Online:

  • This tool! Perfect for quick comparisons
  • GitHub/GitLab diff view
  • Diffchecker.com