Grep like an LLM · part 5 of 6
Ask the history
On this page
Some questions aren't answered by the code as it stands. Why is this check here? Who decided this number? Code shows you what; the history is where the why lives.
What changed here
Before changing an unfamiliar area, look at its recent history:
$ git log --oneline -- services/stock/ 8d04c2b Melt alerts when the freezer fails (#31) 3f2c1aa Track stock per pitch, not per van (#27) b91e44d Add sold-out handling to stock service (#19)
--oneline prints one commit per line, and the path after -- limits
the history to commits that touched that folder. Three lines in, you know
the area is active, what changed recently, and which pull requests to read
if the code raises questions. When you need names and dates, plain
git log shows the same history in full.
When did this appear
For a specific puzzling string, perhaps a constant or a strange condition, ask when it arrived:
$ git log -S 'meltAlert' --oneline 8d04c2b Melt alerts when the freezer fails (#31)
-S finds commits that add or remove the string, meaning you get the
moment it was born and every time it moved. The commit message explains
the intent, and the pull request number it references usually holds the
full discussion. The explanation you couldn't find in the code is often
one -S away.
At your desk
The next time you meet code that makes no sense, pick its strangest
string and run git log -S on it before asking anyone. You'll either
arrive at the answer, or arrive at the right person with the right
question.