CHAPTER 05

Reading history

Something's broken, nobody remembers changing it, and forty commits stand between you and the answer.

Thursday, the following week

Anvesha pings the group chat with a screenshot: the homepage preview you've been sending the Board looks off. The section spacing near the footer has gone from a clean 24px gap to something like 4px — cramped, wrong, definitely not what anyone designed. "Did one of you touch this? It was fine Monday."

Nobody remembers touching it. There have been maybe forty commits since Monday — yours, Rachit's, Anvesha's, and two from Sahil who's been setting up the build config. The bug is real, it's live on the preview, and right now your only lead is "somewhere in the last forty commits."

This is the moment git log stops being a curiosity and starts being a search tool.

1. git log — scanning the whole trail

Plain git log is unusable for this — forty full commit messages scrolling past. You want a shape you can actually scan:

narrowing the search
$ git log --oneline -- src/styles.css # only commits that touched this file
c9d4e5f fix(nav): show mobile menu button below 480px
7d0c2e5 chore: tidy footer spacing variables
3f8a1b2 feat(build): pull in shared spacing tokens

Three suspects out of forty, immediately, just by asking Git "which commits actually changed the file that's misbehaving." That single -- path filter does more work than reading every message would have.

MORE WAYS TO CUT THE LIST DOWN
git log --author="sahil" — only one person's commits. git log --since="3 days ago" — only recent ones. git log --grep="spacing" — only messages mentioning a word. git log -S"padding" — only commits that added or removed the literal string "padding" anywhere in the diff, which is often the single fastest way to find where a specific value came from.

2. git show — opening one suspect fully

"chore: tidy footer spacing variables" sounds exactly like the kind of change that could quietly break spacing. Open it completely — message, author, full diff:

opening the suspect
$ git show 7d0c2e5
commit 7d0c2e5
Author: Sahil
chore: tidy footer spacing variables
 
- --section-gap: 24px;
+ --section-gap: 4px;
/* renamed from --spacing-lg, seemed unused elsewhere */

Found it. Sahil renamed a variable he thought was unused and, in the process, typed 4px instead of copying the original 24px across. Not malicious, not even careless in an obvious way — just a small slip that git show surfaces in about four seconds once you know which commit to point it at.

3. git diff — comparing any two points

git show is one commit in isolation. git diff is for comparing across a range — useful once you want to see everything that changed between "known good" and "known broken":

CommandCompares
git diffWorking directory vs staging
git diff --stagedStaging vs last commit
git diff HEAD~5Working directory vs five commits ago
git diff main..featureTwo branches
git diff 3f8a1b2 c9d4e5f -- src/styles.cssTwo specific commits, one file only

4. git blame — who touched this exact line, and when

Suppose the log filter hadn't been so clean — suppose you just knew "the footer spacing is wrong" and nothing else. git blame annotates every single line of a file with the commit that last changed it:

blame, not accusation
$ git blame src/styles.css -L 18,22
7d0c2e5 (Sahil 2 days ago 19) --section-gap: 4px;
3f8a1b2 (Rachit 5 days ago 20) --nav-height: 64px;

Same answer, arrived at from the opposite direction: instead of guessing which commit to open, you start from the broken line and let Git tell you which commit is responsible. The name in the output isn't an accusation — it's a pointer to context. You now know exactly who to ask "hey, was this rename intentional?" instead of posting "did anyone touch the CSS??" into a group chat and hoping.

5. git reflog — the log of where HEAD has been

Separate from all of the above: git reflog doesn't track your project's history, it tracks your local movements through it — every checkout, every commit, every reset, on this one machine, for about 90 days. It's not what you needed for today's bug hunt, but hold onto it, because in the next chapter you're going to make a genuine mistake, and this is what gets you out of it.

a preview of what reflog looks like
$ git reflog
c9d4e5f HEAD@{0}: commit: fix(nav): show mobile menu button below 480px
7d0c2e5 HEAD@{1}: commit: chore: tidy footer spacing variables
3f8a1b2 HEAD@{2}: commit: feat(build): pull in shared spacing tokens
MAKE THE GRAPH VIEW A HABIT
git config --global alias.lg "log --graph --oneline --all --decorate" — now git lg shows every branch as a visual graph in one line per commit. When the club's history has more than one branch running at once (Chapter 7 onward), this becomes the fastest way to see what's actually going on.
CHECK
You know a bug is somewhere in one file's history but have no idea which commit. What's the fastest path from "no idea" to "found it"?
Blame answers "which commit last touched this exact line" directly — no scanning required. show then gives you the full story of that commit: message, author, diff. Reflog answers a different question entirely (where has my HEAD been), and scanning forty log entries by eye is exactly the slow path blame exists to skip.

You message Sahil the commit hash and a screenshot. He replies within a minute: "oh no, yeah, that was a typo, I meant to keep it at 24." Simple enough fix — except the commit is already sitting in the shared history, two commits behind your current work, with another commit from you already stacked on top of it. Just editing the line again feels wrong somehow. Is there a correct way to undo this specific, already-buried mistake without disturbing anything that came after it?