Course contentsShow
← Data Science
Lesson 1995 of 2,14546. Version Control with GitFree lesson

Committing Changes with git commit

Creating commits with meaningful messages, understanding commit best practices, and viewing commit history basics.

Committing Changes with git commit

You'll learn how to create permanent snapshots of your work with meaningful commit messages, following best practices that make collaboration and code archaeology easier.

What Is a Commit?

After staging files with git add, a commit creates a permanent snapshot in your repository's history. Think of it like saving a game at a checkpoint—you're recording exactly what your project looked like at this moment, along with a note explaining why you made these changes.

Creating Your First Commit

Once you've staged changes, commit them with:

git commit -m "Add initial data cleaning script"

The -m flag lets you write the commit message directly in the command. Without it, Git opens a text editor for you to write a longer message.

Writing Meaningful Commit Messages

Good commit messages answer: "What does this change accomplish?"

Best practices:

  • Start with a verb: "Add", "Fix", "Update", "Remove"
  • Be specific: "Fix null value handling in demographics column" beats "Fix bug"
  • Keep the first line under 50 characters
  • Use present tense: "Add feature" not "Added feature"

Example for data science work:

git commit -m "Add feature engineering for purchase frequency"
git commit -m "Fix median imputation for missing age values"
git commit -m "Update model hyperparameters based on validation results"

Viewing Commit History Basics

See your commits with:

git log

This shows commit IDs, authors, dates, and messages—creating an audit trail of your project's evolution.

Key Takeaway: Commits are permanent snapshots with descriptive messages; write them as if explaining your changes to a teammate who'll read them six months from now—because that teammate is often future you.