Editing and staging
separation of concern: working directory and staging area
We keep the working directory and the staging area (index) separate to acknowledge their different role.
the role of the working directory
The working directory is a playground where changes are not saved, good for exploration and iteration. Its content has no influence on what is saved when we perform a commit.
terminology
This allows us to have files that we don't commit yet or ever: untracked files. If the file is a modified version of one that was committed before, and that it is not staged yet, we call it modified.
When files are added to the staging area, they cease to be untracked or modified: they become staged.
staging area: granularity and storage
The staging area determines what is saved on commit. Having some granularity instead of saving the whole working tree has benefits:
- We may select related changes and commit them as a group.
- We may technically save different portions of a file at a time.
Besides, we may use the index as a temporary storage, in a manner similar of saving checkpoints: This allows to store one version and keep iterating on it, with the ability to revert to the checkpoint if needed.
This is possible because the index is similar to a commit: it has its own list of files, which live in the storage area, and that are decoupled from the working tree.