TIL: Interactive Staging With git add -p
You made changes. Not all of them belong in the same commit. git add -p lets you stage only what you want.
git add -p
Git shows each change hunk by hunk and prompts you. Press y to stage, n to skip, s to split the hunk into smaller pieces.
git add -p src/sdk/index.ts
Target a specific file. Only the changes in that file are shown.
git add -p -- .
The – . limits the scope to the current directory. Useful when you have changes scattered across a large repo.
What if I want to edit a hunk before staging?
Press e at the prompt. Git opens the hunk in your editor. Delete the lines you do not want to stage and save.
Does this work with git reset?
Yes. git reset -p does the same thing in reverse. Unstage specific changes while keeping others staged.