You fixed a bug, renamed a variable, and left a console.log. All three are
about to become one commit that nobody can review.
git add -p walks your diff one hunk at a time and asks whether each piece
belongs in this commit.
y stage this hunk
n skip it
s split it into smaller hunks
e edit the patch by hand
Use s when git bundles two unrelated edits into one hunk — it breaks them
apart so you can take only the one you meant.
But the real benefit isn’t tidy history. It’s that you re-read every line
before it ships, so the debug print never makes it in.
Same picker works elsewhere:
git stash -p stash only part of your work
git restore -p discard only part of it
git reset -p unstage only part of it
Learn it once, get it in four places.
More engineering deep-dives: alekseialeinikov.com/en/blog
#git #github #versioncontrol #developer #programming #devops #codereview #commandline #terminal #bash #softwareengineering #cleancode #productivity #coding #sre
source
