Commits
Understand the idea
A commit is a snapshot of the files plus a pointer to its parent, not a list of edits.
The idea
The stores every tracked file as it was, plus the parent hashes. git show and git diff compute the edit by comparing two photographs. That is why a merge commit can have two parents: two photographs both led to this one.
What changes
git add copies the chosen files from the into the . git commit -m "message" freezes that index, points it at the current HEAD, and moves the branch label forward. git commit --amend -m "message" replaces the tip you have not shared by writing a new hash with the same parent.
| Part | Role | Where you see it |
|---|---|---|
| Snapshot | The files at that moment | git show |
| Parents | The commits this one follows | git log --graph |
| Message | Why this snapshot exists | git log --oneline |
The command
write README.md first draft, then git add README.md, then git commit -m "describe the project". Run git log --oneline --graph. The new node sits above the initial commit, and main points at it. Amend only if this commit is still only yours.
The mistake
Check your graph
You should see two commits, the new one parented on the initial commit, with HEAD on main. git show HEAD prints the snapshot you staged, not a file you forgot to add.
Your repository
write a file, git add it, and git commit. Each commit appears on the graph of this repository.
Step 1
Change the snapshot
In the editor, open README.md and add a second line: What this project is for
Step 2
Compare with the last commit
git diff shows the working tree against the index. The last commit is unchanged until you stage and commit.
Step 3
Stage only that file
The index becomes the next snapshot. Unstaged edits stay out.
Step 4
Check what will be stored
The staged diff is the change the commit will freeze.
Step 5
Commit with a reason
The message says why. The graph grows one node, and main moves to it.
Step 6
Read the stored snapshot
git show prints the commit you just made, not the editor.
The editor edits the working tree. Start a repository and the files appear here.
Commit graph
No commits yet. git init creates the first one.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.