Lesson 1 of 9 · 25m
Reading git log Like a Professional
Query history instead of scrolling it: graph views, pickaxe search, blame that survives reformats.
Your incident channel is on fire because the login flow broke sometime last week, and the only lead is "it worked on Tuesday." Most engineers reach for git log and scroll. Professionals treat the log as a query interface, and this lesson is the query language.
The shape of history
The everyday command is the compact graph view:
git log --oneline --graph --decorate --all--graph draws the branch topology, --decorate labels refs (branches, tags, HEAD), and --all includes every branch, not just yours. Alias it — you'll type it hundreds of times:
git config --global alias.lg "log --oneline --graph --decorate --all"Add --stat to see which files each commit touched, -p for the full diff, and -n 20 to bound the output. To see what a branch adds relative to its base, use the two-dot range: git log main..feature/login-fix — the set of commits reachable from your branch but not from main.
Searching history, not scrolling it
git log filters by author, date, and path:
git log --author="priya" --since="2 weeks ago" -- src/auth/The two searches that matter most are the pickaxe and -G. -S"rate_limit" finds commits where the count of that string changed — i.e., when code containing it was added or removed. -G"rate.?limit" takes a regex and matches commits whose diff mentions it anywhere. For "when did this function appear," -S is almost always the right one.
git show <sha> inspects one commit fully. git blame -L 40,60 -- src/auth/session.py annotates lines 40–60 with the commit that last touched each. Add -w to ignore whitespace-only changes and -C -M to trace lines through moved or copied code.
Pitfalls
- Blame lies after a reformat. A repo-wide prettier or black run makes every line look authored by the formatting commit. Keep a
.git-blame-ignore-revsfile listing those SHAs and setblame.ignoreRevsFile— GitHub and modern git (2.23+) honor it. --followonly tracks one path and is heuristic. If a file was renamed,git log --follow pathhelps, but-Mdiff options are more reliable.- Dates in
git logare commit dates; after a rebase they may all look like today.--pretty=format:"%h %ad %cd"shows author date vs commit date when chronology matters.
Try this
In a repo you work in, run git log -S"def authenticate" --oneline (or any function name you know exists). Find the commit that introduced it, git show it, then git blame -w the function today and see how many different hands have touched it.