git add --patch
A way of staging only some of the changes in a file, by answering yes or no to each hunk Git shows you.
In more detail
Git shows one hunk at a time and asks what to do: y stages it, n leaves it, s splits it into smaller hunks and q quits. It lets one messy afternoon of edits become several commits that each say one thing.
Example
git add --patch recipes.mdRelated terms
- hunk — One block of nearby changed lines in a diff, shown with a few unchanged lines around it for context.
- git add — The command that copies a file's current content into the staging area so it will be part of the next commit.
- staging area — Git's list of exactly what the next commit will contain, kept in the file .git/index; also called the index.
Taught in
- Staging Deliberately: status, add, add --patch — Advanced Git Internals & Distributed Workflows