Code Review: Reading Others' ChangesLesson 6.1
How to read a git diff without getting confused
unified diff format, hunk headers, added vs removed lines, context lines, file headers, binary files in diffs, reading large diffs strategically
A Diff Shows Change, Not State
A diff shows what changed, not what the code currently is. Until you can read a diff fluently, code review is slow and error-prone. The unified diff format is universal โ it's what git, GitHub, and every code review tool uses.
Reading the Unified Diff Format
diff --git a/src/auth/login.js b/src/auth/login.js
index 3f2a1b..9e4c2d 100644
--- a/src/auth/login.js โ old file
+++ b/src/auth/login.js โ new file
@@ -23,7 +23,9 @@ โ hunk: old start,count โ new start,count
function validateLogin(email, password) {
if (!email || !password) {
- return false; โ removed line
+ throw new ValidationError( โ added lines
+ 'Email and password required' โ
+ ); โ
}
return checkCredentials(email, password);
}Reading Large Diffs Strategically
Never start at line 1 of a large diff and read to the end. Start with the file list to understand scope. Then read the test changes โ they tell you what behavior changed. Then read the implementation changes. Test changes first gives you a behavioral summary before you evaluate the implementation.
