The staging area, or index, is where you build your next commit. git add copies a file's current content into the index. git commit turns whatever is staged into the new commit.
The separation lets you choose what goes in: the fix, not the debug print. git add -p goes further and lets you pick single hunks of one file.
git add stages the content, not the file, so edits made after it stay out of the commit until you add them again.
git diff # working files vs staging area
git diff --staged # staging area vs last commit
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
How do you unstage a file without losing the edits in your working copy?git restore --staged <file> (or git reset <file>) puts the index back to HEAD's version. The working file keeps your changes.
What does git commit -a do, and what does it leave out?It stages changes to tracked files, deletions included, then commits. New untracked files still need an explicit git add.
You staged part of a file with git add -p. How do you check exactly what will be committed?git diff --staged shows what goes into the commit. Plain git diff shows what stays behind in the working files.
The staging area, also called the index, is where you build your next commit before you make it.
git add copies a file's current content into the index, and git commit turns whatever is staged into the new commit.
Keeping those two steps apart means I choose what goes in, so the fix gets committed and the debug print stays out.
With git add -p I can go further and stage single hunks of one file.
To check, git diff compares my working files to the index, and git diff --staged compares the index to the last commit.
The catch is that git add stages content, not the file, so edits I make after it stay out of the commit until I add them again.
Weak answers to avoid
Treats staging as a pointless extra stepIt sounds like you've never split a commit. Name what it buys: commit the fix without the debug print, or stage single hunks with git add -p.
Thinks git add tracks the file, not its contentEdits made after git add stay out of the commit until you add again. Say the index holds the content as it was when you ran git add.
Mixes up git diff and git diff --stagedPlain git diff compares working files to the index, so staged changes drop out of it. git diff --staged shows what the commit will hold.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.