Course contentsShow
← Computer Science
Lesson 2173 of 2,87249. Version Control with GitFree lesson

Committing Changes

Record staged changes to the repository with 'git commit' and write meaningful commit messages.

Committing Changes

You'll learn how to permanently record your staged changes in Git's history with meaningful commit messages.

What Is a Commit?

A commit is like taking a snapshot of your project at a specific moment. Once you've staged files using git add, you're ready to save those changes permanently to your repository's history. Think of commits as checkpoint saves in a video game—each one marks a deliberate point you can return to later.

Making Your First Commit

After staging changes, use git commit to record them:

git commit -m "Add user login feature"

The -m flag lets you add a message inline. This message should clearly describe what changed and why.

Writing Meaningful Commit Messages

Good commit messages are crucial for understanding project history. They should:

  • Be concise but descriptive
  • Use present tense ("Add feature" not "Added feature")
  • Focus on the purpose, not just what files changed

Example:

git commit -m "Fix null pointer error in user authentication"

Poor example:

git commit -m "Changed stuff"

Viewing Commit History

Once you've made commits, you own a timeline of your project's evolution. Each commit has a unique ID, author, timestamp, and message—though we'll explore viewing history in later lessons.

Why Commits Matter

Commits create an audit trail. If something breaks, you can identify exactly when it happened. They also enable collaboration by showing who changed what and why.

Key Takeaway: Use git commit -m "message" to save staged changes with a clear, descriptive message that explains the purpose of your changes—commits are the building blocks of your project's history.