Git Blame & Archaeology
Also Known As
git blame
git bisect
git log -S
code archaeology
TL;DR
Using git blame, git log -S, and git bisect to trace when code was introduced, who wrote it, and which commit caused a bug — essential for debugging and context.
Explanation
git blame file.php shows the last commit and author for each line — useful for context on why code exists. git log -S 'string' finds commits where the string was added or removed (pickaxe search) — answers 'when was this function added?'. git log --follow -p file traces the history of a file including renames. git bisect binary-searches commit history to find the first bad commit introducing a bug. git annotate is an alias for blame with more context. Combining these tools turns git history into comprehensive documentation.
Common Misconception
✗ git blame identifies who to blame for bugs — git blame identifies who to ask for context; the goal is understanding why code exists, not assigning fault.
Why It Matters
A mysterious security check with no comment makes sense instantly with git blame — the commit message explains the vulnerability it prevents and links to the issue, avoiding future removal.
Common Mistakes
- git blame showing a formatting commit — use -w to ignore whitespace changes.
- Not using git bisect for regressions — manually checking 50 commits is hours; bisect finds the culprit in 6 steps.
- Assuming the blamed commit explains everything — the PR or issue linked from the commit message has more context.
- Not using git log --follow for renamed files — plain git log stops at the rename.
Code Examples
✗ Vulnerable
# Manual regression hunt — slow:
# Bug appeared 'sometime in the last month'
# Check commit from 30 days ago: bug present? No
# Check commit from 20 days ago: present? No
# Check commit from 10 days ago: present? Yes
# ...
# 2 hours later: found the commit
✓ Fixed
# git bisect — binary search, 6 steps for 64 commits:
git bisect start
git bisect bad HEAD # Current commit has the bug
git bisect good v1.5.0 # This tag was fine
# git checks out the middle commit:
git bisect good # No bug here — move to upper half
git bisect bad # Bug here — narrow further
# ... 4 more steps
# Result: 'abc1234 is the first bad commit'
git bisect reset
# Find when a function was added:
git log -S 'processPayment' --oneline
# Show full history of a file:
git log --follow -p -- src/Payment/Gateway.php
References
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
29
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 11
Perplexity 9
Google 3
Ahrefs 2
SEMrush 2
Majestic 1
Also referenced
How they use it
crawler 26
crawler_json 2
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Low
⚡ Quick Fix
Use git blame -w (ignore whitespace) and git log -S 'search_term' (pickaxe) to understand why code exists — the commit message and linked issue give context that the code itself cannot
📦 Applies To
git
any
🔗 Prerequisites
🔍 Detection Hints
Non-obvious code without blame context; orphaned code with no linked issue or PR; code owned by someone who left the team
Auto-detectable:
✗ No
git
github
gitlab
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Low
Context: File