Lesson
Commits
How a commit object is built, how it links to its parent, and how the branch and HEAD move.
Learning objectives
- Describe the parts of a commit object
- Explain parent links and the commit graph
- Understand how committing moves the branch and HEAD
What a commit stores
A commit object records a tree (the full snapshot of your files), one or more parent pointers, the author and committer, a timestamp, and your message. The commit's hash is derived from all of this, so any change produces a different hash.
The parent link
Each commit points back to the commit that came before it. Following these links backward walks your history. This is what makes the history a graph rather than a flat list.
Moving forward
After git commit, the current branch pointer moves to the new commit, and because HEAD points at that branch, HEAD moves too. Your staging area is cleared.
Try it yourself
Empty folder
Run git init to create a repository.
Working directory
Clean — no uncommitted changes.
Staging area
Nothing staged. Run git add.
Repository
No commits yet.
Make two commits and watch the second link to the first as its parent.
Commands used
git init
git add a.ts
git commit -m "c1"
git add b.ts
git commit -m "c2"
git logCommon mistakes
- • Writing vague messages like 'updates' or 'fix stuff'.
- • Bundling many unrelated changes into one commit.
Best practices
- • Write imperative messages: 'add', 'fix', 'refactor'.
- • Keep commits atomic — one logical change each.
Mini challenge
Make three commits, then use git log --oneline to read the chain of parents.
Open the visualizer to try itSummary
- A commit = snapshot + parent + metadata + message.
- Commits form a graph via parent links.
- Committing moves the branch and HEAD forward.