Reading — step 1 of 5
Read
~1 min readDiff Output
Context Lines & Hunks
A diff usually shows N context lines before and after each change. By default, N = 3.
If two changes are within 2 * context lines of each other, they merge into one hunk. Otherwise they're separate hunks:
File A (10 lines)
File B same except lines 2 and 8 changed
With context=3:
Hunk 1: lines 1-5 (1, 2, 3, 4, 5; change at 2)
Hunk 2: lines 5-10 (5, 6, 7, 8, 9, 10; change at 8)
Adjacent? Hunk 1 ends at line 5 (context for change at 2); Hunk 2 starts at line 5.
They MERGE because they touch.
Larger context = more readable but bigger diffs. Smaller = more compact but harder to grok.
Useful flags:
git diff -U0— no context (just changes)git diff -U10— 10 lines context (very readable)git diff -W— show whole function for any change (diff-ignore-all-space friend)
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…