Sub topic 6
Reading the diff in a deliberate order
This chapter assumes you know basic Git (branches, diffs, staging) and can read code in at least one language. It also assumes you have already triaged the change set with git status and git diff --stat, as covered in the previous chapter. Now you read the code itself.
Why order matters
A multi-file diff is not a story. Git lists files alphabetically, so a helper file can appear after the code that depends on it. If you read in that order, you judge details before you know what they are for. A deliberate order lets you check the shape of the change first and the line-level detail last.
The order below runs from the outside in:
- The file list, checked against the task.
- Interfaces: signatures, types, public names, configuration keys.
- Implementation behind those interfaces.
- Tests, read last for content but checked early for deletions (the next chapters cover this in depth).
Step 1: Compare the file list with the task
Start with the names, not the contents.
git status --short
git diff --name-statusFor each file, ask whether the task required touching it. A rename of a config loader should touch the loader, its callers and its tests. A change in src/billing/invoice.py needs an explanation. Anything unexplained goes on a list to question later. Do not stop to investigate yet, since a later file may explain it.
Step 2: Read interfaces before bodies
Interfaces are where a change spreads. A renamed function, a new parameter, or a changed return type affects every caller. Limit the diff to the lines that define them. Git can show the enclosing function name in each hunk header, which helps you find signatures quickly.
git diff -U0 | grep -nE '^[+-](def |class |export |public |func )'Adjust the pattern to your language. With each changed signature, check three things:
- Is the new name or parameter used consistently across all files?
- Does it exist in the project or its dependencies? Agents sometimes call functions that look plausible but do not exist.
- Did a default value, return type, or error behavior change without being asked for?
Step 3: Read the implementation
Now read the function bodies, one file at a time, starting with the files closest to the core of the task. Refactors that move code create noisy diffs. Two options reduce the noise:
git diff --color-moved=zebra # moved blocks get a distinct color
git diff -w # ignore whitespace-only changesMoved code is shown in different colors from code that was really edited. Spend your attention on the edited lines. A block that moved and also changed one condition is the case most likely to slip through, so look at zebra-colored blocks for small differences.
While reading, keep these questions in mind:
- Does each branch, error path, and edge case behave as before, unless the task said otherwise?
- Were any checks, validations, or log lines removed?
- Is there new code that nothing calls?
Step 4: Check the tests for deletions first
Read test changes after the implementation, but run one quick scan early. It catches the most serious problem, which is tests changed to fit the code.
git diff -- tests/
git diff -U0 | grep -nE '^\+.*(@pytest\.mark\.(skip|xfail)|# noqa|# type: ignore)'Keep a running list
As you read, write down each question in one place: the file, the line, and what concerns you. Do not fix things as you go. At the end, you will see which concerns share a cause. Several oddities often come from a single misreading of the task, and one corrective message can resolve them all.
Exercise
The agent's diff shows src/billing/invoice.py changed, but your task was only to rename the config loader. At which step of the review order do you notice this, and what do you do with it at that point?
Show answer
You notice it in step 1, when you compare the file list with the task. Add it to your running list of questions without investigating yet. Continue reading, because a later file (such as an interface change) might explain the edit. If nothing explains it, ask the agent to revert that file.
Exercise
Why read changed function signatures before function bodies?
Show answer
Signatures show where the change spreads to callers and which behavior contracts changed. Knowing them first lets you judge each body against the intended interface, and it helps you spot invented functions and inconsistent renames early.