CurriculumGit Basicsgit commit — Saving Snapshots
Lesson 5 of 683%
Beginner8 min+80 XP

git commit — Saving Snapshots

git commit permanently saves your staged changes as an immutable snapshot in history. Each commit gets a unique SHA-1 hash, stores your name, email, timestamp, message, and a pointer to the parent commit.

01.Anatomy of a Good Commit Message

Write commit messages in imperative mood, present tense: "Add login form" not "Added login form". Keep the subject line under 72 characters. Add a blank line, then a body explaining WHY (not what — the diff shows what). Reference issue numbers: "Fix crash on logout (closes #42)".

Commit Timeline
a1b2c3d
init
b2c3d4e
feat
c3d4e5f
fix
d4e5f6a
HEAD

02.Commits Are Snapshots, Not Diffs

Git stores complete file snapshots per commit — not just what changed. This makes operations like branch switching instantaneous regardless of history length. The diff you see in git log is computed on-the-fly by comparing two consecutive snapshots.

Git's Three Areas
📁
Working Dir
Your files
→ git add
📋
Staging Area
Prepared
→ git commit
🗄️
Repository
.git/ history

Commands

commands — click to reveal output
$
git commit -m "Add user authentication"
Commit staged files with an inline message
$
git commit
Open your text editor to write a detailed multi-line message
$
git commit -am "Fix typo in README"
Stage all tracked modified files AND commit in one step
$
git commit --amend -m "Better message"
Rewrite the last commit message (only before pushing!)
$
git log --oneline
View compact commit history
▼ show output
KNOWLEDGE CHECK

What does Git store in each commit object?

Rate this lesson:
PreviousNext Lesson