Skip to content
Justice Tech School

Staging Parts with add -p

git add -p stages selected hunks. Here we feed answers so it runs without prompts.

Example
printf 'a\nb\nc\n' > f.txt && git add f.txt && git commit -qm base
sed -i 's/a/A/;s/c/C/' f.txt
git add f.txt
git diff --staged --stat | tail -1

Result

 1 file changed, 2 insertions(+), 2 deletions(-)

Exercise

Interactive hunks.

git add 

Quiz Test

What does -p let you do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.