Chapter 1 · Practice 3 of 4
Review and stage changes in pieces with git add -p
Why it matters
git add . stages everything, including debug prints, temporary files and unrelated edits. Staging in pieces keeps commits focused and doubles as a quick self review: you read every line before it is committed.
git add -pwalks through your changes hunk by hunk so you choose what belongs in this commit.git diff --stagedshows exactly what will go in. Run it before every commit.git restore --staged <file>unstages a file you staged by mistake, without losing your edits.
Example
git add -p # pick hunks interactively
git diff --staged # check what will be committed
git restore --staged app.log # unstage a file, keep the changes
git commit