Reading a Small Git Diff
A line diff shows how one selected version of a file changes into another, with nearby unchanged lines for context.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Find the compared versions
An ordinary working-tree diff compares unstaged tracked changes to the index. A staged diff compares the selected next contents to the last commit by default. The working tree and index explain why these comparisons can show different edits.
Follow removed and added lines
Changing a limit from 10 to 12 appears as a removal and an addition even though the same setting remains. Read the surrounding unchanged lines to identify its rule, and verify that a boundary test exercises the new limit.[1]
Connect a changed line to its context and effect
Suppose a diff changes a default limit from twenty to fifty. Adjacent lines show when that default applies. A caller supplying its own limit observes no effect from this particular assignment. A review should examine the default case and check a caller that overrides it. See default arguments and policy.
Context: limit is used for previews
-default_limit = 20
+default_limit = 50
Expected: one omitted option yields 50, explicit 5 still yields 5
Distinguish file identity and content changes
A diff can report removal, addition, rename or mode changes. A rename can contain content edits too. Compare the resulting behavior and check any paths referenced by dependent files.