What a commit actually is
A commit is a full snapshot with a parent, not a list of changes.
A snapshot, not a diff
Git stores each commit as a complete snapshot of the tracked files, plus a pointer to the commit before it. The diffs you read are calculated on demand by comparing two snapshots — they are a view, not the storage.
This is why switching branches is fast and why Git can show you any historical state instantly: it is not replaying changes, it is reading a snapshot. Identical files across commits are stored once, so snapshots are far cheaper than they sound.
Every commit carries its parent, which is what makes history a chain rather than a pile. A commit id is a hash of the content, the parent and the metadata — so changing anything about a commit, including its message or its parent, produces a different id. That single fact explains most of what rebase does and why it rewrites history.
The staging area is the point
There are three places a file can be: your working directory, the staging area, and the repository. `git add` copies the current state of a file into staging; `git commit` turns whatever is staged into a snapshot.
The gap between them is a feature, not bureaucracy. It lets you commit part of what you changed — fix a bug and tidy some formatting, then commit only the fix. `git add -p` walks the changes hunk by hand and is the fastest way to stop writing commits that do three unrelated things.
One consequence catches everyone once: staging captures the file as it was when you staged it. Edit it again and you have a staged version and a newer unstaged one, and `git commit` takes the staged one. `git status` says so, in those words, which is why reading it is worth the two seconds.
Worked examples
See exactly what would be committed
/git diff --staged/Against:
Run before every commitgit diff alone shows the opposite — what is not staged. The two are easy to confuse and show different things.
Check yourself
Practice questions written for this lesson — not past exam papers.
Practise every question in this subject
What does a commit store?
You stage a file, then edit it again, then commit. What is committed?