Sub topic 5
Reading the diff line by line
This chapter assumes you can read a unified diff, run basic Git commands, and have already checked the change against its requirement. Here you read the change itself, carefully and in a fixed order.
Why the diff, not the file
Open the diff, not the finished file. A finished file looks coherent, and that coherence hides what changed. The diff shows exactly what the assistant added, removed, and touched outside your request. Everything you accept is in the diff, so everything you review should be too.
Start wide, then go narrow
Begin with the overall shape, then read each hunk (a contiguous block of changed lines).
git diff --stat
git diff
git add -pgit diff --statlists changed files and line counts. Look for files you did not expect, such as lockfiles, configs, or unrelated modules.git diffshows the full change. Read it top to bottom.git add -pwalks through hunks one at a time. Answeryto stage a hunk,nto skip it, andsto split a large hunk. Only staged hunks are accepted, so this turns review into an explicit decision per hunk.
What to ask of every changed line
For each added or removed line, ask four questions.
- Does this line serve the requirement? If you cannot say why it exists, treat it as suspect.
- Do I understand what it does? Do not accept code you cannot explain.
- Is every name real? Check that functions, methods, and arguments exist in your codebase or library version. Packages and APIs get their own chapter, but a name you do not recognize is a flag to note.
- What did it remove? Deleted lines are easy to skim past.
Watch for what the assistant did not mention
AI changes often include extras that the summary leaves out. Look for these in the diff:
| Pattern in the diff | Why it matters |
|---|---|
| Removed or weakened checks, asserts, or error handling | The change may "fix" a failure by hiding it |
| Edited or deleted tests | The tests may now match the code instead of the requirement |
| Renamed variables or reformatted unrelated code | Noise hides real changes and inflates the review |
| Broad `except:` blocks or silent `pass` | Errors get swallowed |
| New config, flags, or dependencies | They change behavior beyond the request |
| Comments that claim more than the code does | The comment may describe intent, not behavior |
Read the deletions too
Here is a hunk that looks like a small cleanup.
def load_config(path):
- if not os.path.exists(path):
- raise FileNotFoundError(path)
- with open(path) as f:
+ try:
+ with open(path) as f:
+ return json.load(f)
+ except Exception:
+ return {}The addition looks tidy. The deletions show the real behavior change. A missing file used to raise an error, and now it silently returns an empty config. Callers will run with defaults and no warning. The diff made this visible, and the finished file would have hidden it.
Keep your own notes
When something looks wrong, write down the line and the question, then keep reading. Finishing the pass before you start fixing gives you the whole picture. Several small issues in one hunk often point to one misunderstood requirement.
Exercise
In a diff, an AI assistant replaced a validation block with a try/except that returns a default value, and its summary says only "simplified loading". Which part of the diff do you read most closely, and why?
Show answer
The removed lines. They show the validation and error raising that no longer happens. The summary describes the added code, but the deletions reveal that failures are now silently hidden. Check whether callers depended on the error, and revise or reject the hunk if they did.