How do I interactively unstage a particular hunk in git?

Andrew Grimm picture Andrew Grimm · Mar 4, 2011 · Viewed 11.7k times · Source

In git, if I have a couple of hunks from the same file staged in my index, how can I interactively unstage one of them?

Is there any alternative to unstaging the entire file, and then re-staging the hunks I want to keep, or manually undoing the changes to the working copy, and then interactively adding those undone changes?

Answer

Aasmund Eldhuset picture Aasmund Eldhuset · Mar 4, 2011

Try git reset --patch filename; this should do the opposite of git add --patch, according to the documentation. The short form -p also works for both commands.