Diff is one of the most useful concepts in a developer's toolkit — and also one of the most underused outside of version control. Once you understand how it works, you start seeing uses for it everywhere: comparing API responses, reviewing config file changes, spotting the difference in two versions of a data export, checking what a colleague changed in a document.
DevToolShack has two diff tools: the Text Diff Checker for line-by-line text comparison and the Diff Checker for side-by-side views. Both are free, browser-based, nothing stored.
How Diff Works
The diff algorithm compares two texts line by line and identifies the minimum set of changes (insertions and deletions) that transforms one into the other. This is the same algorithm underlying git diff, pull request reviews, and merge conflict resolution.
The output marks lines as:
- Unchanged — appears in both versions (shown without marking, or in grey)
- Deleted — appears in the original but not the new version (typically red, prefixed with
-) - Added — appears in the new version but not the original (typically green, prefixed with
+)
Reading Unified Diff Format
The unified diff format (what git diff produces) is the standard for patch files and code review tools:
--- a/config.json
+++ b/config.json
@@ -1,6 +1,7 @@
{
- "timeout": 30,
+ "timeout": 60,
"retries": 3,
+ "debug": false,
"endpoint": "https://api.example.com"
}
Reading the header: @@ -1,6 +1,7 @@ means "in the original file, this chunk starts at line 1 and covers 6 lines; in the new file, it starts at line 1 and covers 7 lines."
Developer Use Cases
Comparing API Responses
When an API response changes unexpectedly between environments or versions, paste both responses into the Text Diff Checker. It immediately highlights exactly which fields changed, were added, or were removed — without having to read through hundreds of lines of JSON manually.
Config File Review
Before deploying a configuration change, diff the current config against the proposed new one. Catches accidental deletions, typos, and unintended changes that are easy to miss when reading a file in isolation.
Document Version Comparison
When a client or colleague sends a "revised" version of a document with no track changes, diffing the plain text of both versions immediately surfaces what changed. Much faster than reading both documents side by side.
Data Export Verification
After running a migration or transformation, diff a sample of the before and after data to verify changes are exactly what was expected and nothing unexpected changed.
Debugging Intermittent Issues
When the same request produces different results at different times, capture both responses and diff them. The difference often points directly to the bug — a timestamp that shouldn't be changing, a field that flips between values, an extra record appearing.
Command-Line Diff
# Basic diff — shows what changed between two files
diff file1.txt file2.txt
# Unified format (same as git diff) — most readable
diff -u file1.txt file2.txt
# Ignore whitespace changes
diff -w file1.txt file2.txt
# Ignore blank lines
diff -B file1.txt file2.txt
# Case-insensitive
diff -i file1.txt file2.txt
# Recursive directory diff
diff -r dir1/ dir2/
# Generate a patch file
diff -u original.txt modified.txt > changes.patch
# Apply a patch
patch original.txt < changes.patch
Git Diff Workflows
# What changed since last commit
git diff
# What changed in the staging area
git diff --staged
# Changes between two commits
git diff abc123 def456
# Changes between two branches
git diff main feature/my-branch
# Only show file names that changed
git diff --name-only
# Word-level diff (not line-level)
git diff --word-diff
Beyond Text: Semantic Diff
Standard diff compares text line by line, which can produce noisy output for reformatted code. For example, if a JSON file is reformatted but the data is unchanged, a line-level diff shows every line as changed. Better approaches for structured data:
- JSON diff — compare the parsed data structures, not the raw text. Tools like
json-diffonly show semantic changes. - Semantic diff for code —
difftasticunderstands code syntax and produces diffs based on the AST rather than raw text, dramatically reducing noise. - Format first, then diff — run both versions through the JSON Formatter to normalize whitespace before diffing. This eliminates formatting noise and shows only real data changes.