Hunk
Definition
A hunk is a contiguous block of changes in a text-based file comparison.
A hunk groups adjacent changes of a file in a diff representation. It contains added or removed lines and usually unchanged context lines for orientation. A file comparison can include multiple hunks; they are not standalone commits.
Simply explained
You see a small excerpt with the changed lines and some surrounding context. This way you can view a change separately from the rest.
Why it matters in practice
Change blocks help to review adjustments selectively and, if necessary, prepare only certain changes for a commit.
Example from business
Possible example: A file contains a bug fix and an independent text change; the team initially stages only the appropriate hunk with git add -p.
Limits and pitfalls
- Spatially separated blocks can be technically dependent on each other. Partial staging should therefore be checked for a runnable and understandable intermediate state.
Origin & history
Text-based diff and patch methods group changes with context. Git also uses this representation for interactive selection of individual adjustments.
Use in mid-sized companies
- Development teams can review change blocks individually before a commit and selectively stage changes that belong together logically.
Frequently asked questions
Is a hunk always a complete technical change?
No. The grouping is based on line proximity and context, not on the meaning of the code.
Sources
- o. J., git-add – Interactive mode und Patch-Auswahl · Git-Projekt, o. J., git-add – Interactive mode und Patch-Auswahl
Editorially reviewed on: