git reset --patch
(or git reset -p
) does what you want.
The relevant bit of the documentation:
git reset (--patch | -p) [] [--] […]
Interactively select hunks in the difference between the index and (defaults to HEAD). The chosen hunks are applied in reverse to the index.
This means that git reset -p is the opposite of git add -p, i.e. you can use it to selectively reset hunks. See the “Interactive Mode” section of git-add(1) to learn how to operate the --patch mode.
Note that git reset
(applied on paths) does match git add
— the latter stages files or chunks while the former unstages them, and so git reset
supports the --patch
option just like git add
does.
You might also be interested to learn about git checkout --patch
(or git checkout -p
).