Saving Snapshots (Commits)
A commit is a snapshot of your project at a specific moment in time. It's like taking a photo and labeling it so you can find it later.
Creating a Commit
Once you've staged your files, create a commit with:
git commit -m "Your message here"
The -m flag lets you add a message describing what changed.
Writing Good Commit Messages
Your commit message should explain why you made the change, not just what changed.
Good Messages:
Add user login form with validationFix bug where prices showed negative valuesRefactor database queries for better performance
Bad Messages:
Update filesFix stuffasdfasdf
Understanding Commit Hashes
Every commit gets a unique identifier called a SHA hash:
a1b2c3d4e5f6789...
This 40-character string is like a fingerprint - no two commits will ever have the same hash. Usually, you only need the first 7 characters to identify a commit.
What's Inside a Commit?
Each commit stores:
| Component | Description |
|---|---|
| Tree | Snapshot of all your files |
| Parent | Link to the previous commit |
| Author | Who made the commit |
| Message | Your description |
| Timestamp | When it was created |
| Hash | Unique identifier |
The Polaroid Metaphor
Think of each commit as a polaroid photo:
- The photo itself is the snapshot of your files
- The message is what you write on the white strip below
- The timestamp is when you took it
- The hash is like a serial number on the back
Try It Out!
Use the interactive playground to create your first commits.
Visual Mode: Click "Create Commit" after staging files Command Mode: Typegit commit -m "your message"
Watch the commit appear in the graph with its unique hash!