In this lesson, you will learn how to finalize your work by transforming your staged changes into a permanent, descriptive snapshot in your project's history.
From Staging to Snapshot
Up until now, you have been selecting changes to "stage" using git add. Think of the staging area as a preparation desk. You have carefully laid out the files you want to include, but Git hasn't saved them into your project's official history yet. To do that, we use the commit command.
A commit acts as a permanent snapshot of your project at a specific moment in time. When you commit, you are essentially telling Git: "Take everything on the preparation desk and glue it into the project history forever."
Writing the Commit Message
Every commit requires a message. This is not just a label; it is a professional record of why you made these changes. A good commit message serves as a time machine, helping you (and your teammates) understand the evolution of the code months or years down the road.
To create your snapshot, use the following command in your terminal:
git commit -m "Describe your changes clearly and concisely"
The -m flag stands for "message," and the text inside the quotes should summarize what you accomplished in this batch of work. For example, instead of saying "fixed stuff," use a descriptive message like "Add header styling to the homepage."
Why Professionalism Matters
Because these messages become a permanent part of your project’s history, clarity is vital. Imagine your future self looking back at this snapshot. If your message is descriptive, you will understand exactly what happened without having to inspect the code line-by-line.
- Stage your files: Use
git addto prepare your changes. - Commit with intent: Use
git commit -m "Your descriptive message here"to save the snapshot.
Once the command runs, Git will provide you with a unique identifier (a long string of characters) confirming that your snapshot has been safely recorded in the repository.
Key Takeaway: A commit is a permanent snapshot of your work, and a descriptive commit message is the essential documentation that makes your project history readable and maintainable.