🔥 0
0
Lesson 4 of 10 20 min +125 XP

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 validation
  • Fix bug where prices showed negative values
  • Refactor database queries for better performance

Bad Messages:

  • Update files
  • Fix stuff
  • asdfasdf

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:

ComponentDescription
TreeSnapshot of all your files
ParentLink to the previous commit
AuthorWho made the commit
MessageYour description
TimestampWhen it was created
HashUnique 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: Type git commit -m "your message"

Watch the commit appear in the graph with its unique hash!

Tracking Changes