History Archaeology
7 pages · ~5 min✓ Reviewed
Builds on Tags, Releases and Cherry-pick. Next up: Git Hooks & Automation.
History Archaeology Mental Model
1. Question to tool
| Question | Tool |
|---|---|
| Which commits touched X? | log filters |
| String appeared or vanished? | log -S / -G |
| Who last changed this line? | blame |
| What did that commit do? | show |
| Which commit broke it? | bisect |
2. The history model
- History = DAG of immutable snapshots
log,blame,showonly read: always safegit logwalks from HEAD back through parentsA..B= commits in B not in A; bounds the search
- Narrowpath, author, date, message
- Pick shalog --oneline
- Inspectshow sha
3. Blame goes one layer
- Blame shows the last commit to touch a line
- Not the commit that introduced the idea
- Go deeper:
-Lrange orblame <sha>^
bash
git blame -L 40,60 app.py git blame a1b2c3d^ -- app.py
Reformat trap
The last toucher may be a whitespace commit. Dig past it.
- Is blame safe to run? Yes, read-only.
- Commits in B but not A?
git log A..B
Filtering git log
1. Filter by metadata
| Flag | Keeps commits... |
|---|---|
--author="name" | by that author |
--since="2 weeks ago" | after a date |
--until=2026-01-01 | before a date |
--grep="fix" | message matches regex; -i ignores case |
-- path/file | that touched the path |
--follow | one file, across renames |
Double dash
Put -- before the path, or Git may read it as a branch name. --follow works on a single file only.
2. Shape and detail
Pickaxe Search: log -S, -G and -L
1. -S and -G
git log -S"foo": commits where the count of foo changed- Finds when a symbol appeared or vanished
git log -G"regex": a added or removed line matches, even if the count is same--pickaxe-regexlets -S take a regex
| -S | -G | |
|---|---|---|
| Tests | count change | any changed line |
| Pattern | fixed string | regex |
| Noise | low | higher |
| Catches | add / remove | moved or edited lines |
2. Narrow the hunt
git blame and git show
1. git blame
git blame file: last commit, author, date per line-L 40,60or-L :funcNamelimits the range-wskips whitespace,-Mmoved lines,-Clines copied from other files
2. Skip noise, go back
--ignore-rev <sha>skips one bulk-format commit- Set
blame.ignoreRevsFileto apply the list automatically blame <sha>^ -- file: file just before that commit, finds the previous author
bash
git blame --ignore-revs-file .git-blame-ignore-revs f git config blame.ignoreRevsFile .git-blame-ignore-revs git blame abc123^ -- f
3. git show and the why
| Command | Prints |
|---|---|
git show <sha> | message + diff |
git bisect: Binary Search for a Bad Commit
1. Workflow
- bisect start
- bisect badcurrent is broken
- bisect good <sha-or-tag>known working
- Test midpointmark good or bad
- first bad committhen bisect reset
- Shortcut:
git bisect start <bad> <good> - Commit can't be tested:
git bisect skip - About log2(N) steps: 1000 commits ≈ 10 steps
git bisect resetreturns to your original branch
2. Automate with run
| Exit code | Meaning |
|---|---|
0 | good |
1-127 except 125 | bad |
125 | skip |
128+ | abort |
Archaeology Cheat Sheet
1. Dig Through History
| Question | Command |
|---|---|
| Commits touching a file | git log --follow -p -- path |
| Who last changed a line | git blame -w -M -L 40,60 file |
| String added or removed | git log -S"str" -p --all |
| Changed line matches regex | git log -G"regex" |
| History of a function | git log -L :funcName:file |
- -S fires when the string's count changes
- -G fires when a changed line matches the regex
2. Find the Breaking Commit
- Exit 0 = good, 1-127 = bad
Check yourself
A commit changes timeout=30 to timeout=60. Which lists it: git log -S"timeout" or git log -G"timeout"?
- -S misses it: the count of
timeoutis unchanged - -G finds it: a changed line matches the regex
-S"timeout=30"would find it, since that count drops
Your git bisect run script exits 2 when the build breaks. What happens?
- Exit 2 counts as bad, since 1-127 except 125 means bad
- An unbuildable commit gets blamed wrongly
- Exit
125to skip untestable commits
Blame points at a 'reformat code' commit. How do you reach the real author?
- Add
-w, or--ignore-rev <sha> - Or re-blame with
git blame <sha>^ -- file
Bisect printed 'first bad commit', yet git status says detached HEAD. Why?
- Bisect leaves you on a tested commit