Frequently Asked Question
What is the staging area (index) and why does Git have one?
The index, also called the staging area, is an intermediate region between the
working directory and the repository. When you run git add file, Git does not commit
that file; it records its current contents in the index, marked ready for the next
commit. When you finally run git commit, only what is in the index goes into the new
snapshot, anything else you happened to edit on disk stays uncommitted.
The reason for this extra layer is that a commit ought to be a coherent, reviewable
unit of change. If you have spent the afternoon fixing three unrelated bugs, you do not
want them all bundled into one commit. The index lets you stage the hunks belonging to
one fix, commit them with a message describing only that change, then stage and commit
the next fix separately. git add -p is the killer feature here: it walks you through
each modified region of each file and asks whether you want to stage it.