Version control · foundation
Git commit
A Git commit is an immutable history object that records a project tree, parent commit references, author and committer metadata, and a message; its object ID is derived from its content.
Why it matters
Understanding commits as snapshots in a parent graph clarifies staging, history rewriting, merging, reverting, and why amending produces a different commit rather than editing one in place.
Mental model
How to reason about git commit
The working tree is what you edit, the index is the proposed next snapshot, and commit writes that indexed snapshot with links to its parent history.
Analogy
The index is a tray of pages selected for publication. Committing binds exactly that tray into a numbered edition that cites the previous edition as its parent.
Examples
See the boundary, not just the happy path
Worked example · Commit selected changes
git add src/parser.ts && git commit -m "Handle quoted fields"The commit includes the entire index: the parser change plus anything staged earlier. Unstaged edits stay out, so review git diff --staged first.
Worked example · Inspect the object
git show --stat HEADHEAD resolves to a commit whose comparison with its parent is displayed, even though the commit itself records a full tree snapshot.
Useful contrast · Amend rewrites identity
git commit --amendChanging the snapshot, metadata, message, or parent creates a new object ID; collaborators may still reference the old commit.
Common mistakes
Misconceptions to remove early
Thinking a commit stores only a patch
Git can display parent-to-child differences efficiently, but the commit points to a complete project tree rather than defining itself as a diff.
Committing without reviewing the index
The index can differ from both the working tree and HEAD. Review git diff --staged so the commit boundary matches the intended change.
Quick check
Can you predict the result?
1. Which state supplies the file snapshot for a normal git commit?
- • The index, also called the staging area
- • Every untracked file on disk
- • Only the most recently edited file
2. Why does amending a commit change its object ID?
Keep building