Snapshots, Not Copies
Saving a copy of a file called report-v2 records the new contents, but not
what changed, who changed it or why, and not which other files changed at the
same time. Git records something richer. Each commit is a snapshot of every
file Git is tracking in the project, taken at one moment, together with:
- the author's name and email (the settings from the previous lesson);
- the date and time;
- a message describing the change;
- a link to the commit that came before it, called its parent.
Because every commit points to its parent, the commits form a chain: the project's history. Following the chain backwards takes you through every recorded state of the project.
A snapshot does not mean Git stores every file again. Content that has not changed since an earlier commit is reused, so recording a change to one file in a large project stays small.
Git identifies each commit by a long string of letters and digits, called the
commit ID, calculated from the commit's contents. Git usually shows only the
first several characters, such as 13a88ef. Each commit gets its own ID, and
changing anything in a commit would produce a different ID. The IDs in this
course are illustrative: yours will differ.
Three Places a Change Passes Through

Git works with three places, shown from top to bottom in the diagram:
- The working tree is the set of files you see in the project folder and edit with your usual tools. Git does not record anything just because you edited a file.
- The staging area, also called the index, holds the snapshot you are
preparing for the next commit.
git addcopies a file's current contents from the working tree into it. - The repository holds the commits. It lives in a hidden folder called
.gitat the top of the project.git commitrecords the staging area as a new commit, whose parent is the previous commit.
At the bottom of the diagram, main is the branch name from the previous
lesson. It labels the newest commit and moves forward each time you commit.
Branches get their own module later.
The staging area is what lets you choose what goes into a commit. If you edited three files but only two belong to one change, you stage those two and commit them, leaving the third for a separate commit. The next lessons rely on this.
Following One File Through
Here is one file, todo.txt, followed through two commits. Each row shows what
each place holds after the step, and what git status, the command that
compares the three places, reports. In the table, "milk" stands for the version
of the file containing only "Buy milk", and "milk, bread" for the version with
both lines.
| Step | Working tree | Staging area | Repository | git status reports |
|---|---|---|---|---|
1. Create todo.txt containing "Buy milk" | milk | Nothing for this file | No commits | Untracked file |
2. git add todo.txt | milk | milk | No commits | Change to be committed |
3. git commit | milk | milk | Commit 1: milk | Nothing to commit |
| 4. Add a line, "Buy bread" | milk, bread | milk | Commit 1: milk | Change not staged |
5. git add todo.txt | milk, bread | milk, bread | Commit 1: milk | Change to be committed |
6. git commit | milk, bread | milk, bread | Commit 2 (parent: 1) | Nothing to commit |
Two details in this table catch people out.
After step 3, the staging area is not empty. It still holds the snapshot that
was just committed, and becomes the starting point for the next one. git status shows nothing to commit because the three places agree, not because
the staging area is empty.
In step 4, the edit exists only in the working tree. Running git commit at
that moment creates no commit at all: Git reports no changes added to commit,
because the staging area still matches commit 1. Only what is staged gets
committed.
Reading git status
git status reports the differences between the three places, in these
groups:
| Group | Meaning |
|---|---|
| Untracked files | Files in the working tree that Git has never been asked to track |
| Changes not staged for commit | The working tree differs from the staging area |
| Changes to be committed | The staging area differs from the last commit |
| Nothing to commit, working tree clean | All three places agree |
One file can appear in two groups at once. That happens when you stage a version and then edit the file again: the staged version differs from the last commit, and your newer edit differs from the staged version.
Common Misconceptions
- "Committing saves my files." It records the staging area. Edits you have not staged stay out of the commit.
- "The staging area empties after each commit." It holds the complete next
snapshot;
git statusonly shows how it differs. - "Each commit stores a full copy of every file." Unchanged content is reused between commits.
- "The
.gitfolder is just settings." It holds the whole history. Deleting it deletes every commit.
Check Your Understanding
You create a new file, todo.txt, containing "Buy milk", and run
git add todo.txt. Before committing, you add a second line, "Buy bread".
- Predict what
git statusshows fortodo.txt. - If you run
git commitnow, which version of the file does the commit record? - What would you do to include both lines in the commit?
Answer and Reasoning
todo.txtappears twice: under "Changes to be committed" as a new file, because the staged version is not in any commit yet, and under "Changes not staged for commit" as modified, because the working tree now differs from the staged version.- Only "Buy milk". The commit records the staging area, which still holds the
version from when you ran
git add. - Run
git add todo.txtagain before committing. That copies the current version, with both lines, into the staging area.
You can check these predictions yourself after the next lesson, which creates a real repository.