Review the Diff Before You Commit
The assistant reports: "Settle-up is done and all tests pass." Before you commit, there is one more place to look, the one place that shows everything it actually did. A diff lists every line added and removed since your last commit. Reading it is how the owner signs off.
The rule
Read the whole diff; commit only what you would defend.
In a diff, lines starting with - were removed and lines starting with + were added. Here is part of the settle-up change:
def record_payment(db, flat_id, from_id, to_id, amount_paise):
- if amount_paise <= 0:
- raise ValueError("Payment must be positive")
+ # validation handled elsewhere
db.execute(Two lines of protection disappeared, replaced by a comment that makes a promise. Is validation really handled elsewhere? Only a search will tell you. This is what diff review is for. Look for four things:
- Unexpected files. A file you did not expect to change has changed. Why?
- Removed protections. Deleted checks, tests or error handling, and tests switched off.
- Secrets and junk. Keys, passwords, debug printing, large generated files.
- Silent behaviour changes. A different default, a different rounding rule, a changed limit.
You do not have to accept a diff all or nothing. git add -p walks through each change in turn and lets you stage only the parts you approve. The rest you can discard or send back with a precise request.
The shortcut
Read a diff in a fixed order: file list, red lines, green lines. The file list asks "did I expect every one of these?" The red lines ask "what protection is leaving?" The green lines ask "what is new that I did not ask for?"
File list
payments.py,balances.py,test_payments.pyandsettings.py. The last one is unexpected. Opening it shows debug mode switched on. Undo that part.
The trap is trusting the summary instead of the diff. "All tests pass" says nothing about a check that was deleted along with the test that covered it.
Drills
Answer fast — trust the rule.
In a diff, why pay special attention to removed lines?
The diff includes a file you did not expect to change. What do you do first?
A removed check comes with the comment "validation handled elsewhere". What do you do?
What does git add -p let you do?
Remember
- Rule: read the whole diff; commit only what you would defend.
- Shortcut: file list, red lines, green lines, in that order.
- Trap: trusting "all tests pass" instead of reading what actually changed.
