DEV Community

Cover image for Write Good Commit Messages
IKITAMA CODES
IKITAMA CODES

Posted on

Write Good Commit Messages

Write Good Commit Messages!

Introduction: Why Commit Messages Matter

Commit messages are often overlooked by developers, but they play a crucial role in collaborative project management. A good commit message helps your team—and your future self—understand the changes made without having to read every line of code. Unfortunately, many beginner developers (just like me by the way 😁) make the mistake of using vague messages like "fix" or "done," which makes the Git history impossible to follow.


The Problem with Bad Commit Messages

Here are some common examples of bad commit messages:

  • "fix"
  • "done"
  • "update"
  • "test"

These messages don’t explain what actually changed in the code. When you have dozens of commits like these in your history, it becomes very difficult to track the project's evolution. It also makes it harder for your team if they need to backtrack to a specific bug or change.


Why is this a Problem?

Vague commit messages present several issues:

  1. Lack of clarity: They provide no information about what was changed.
  2. Unusable Git history: When you want to roll back or review the project’s progress, you’re lost in a sea of meaningless messages.
  3. Harder collaboration: Your teammates also don’t know what you did, making collaboration more difficult.

The Solution: Use "Badges" to Structure Your Commits

To make your commit messages clearer, use "badges" or specific keywords at the beginning of the message. This helps quickly identify the nature of the change. Here are a few examples:

  • [fix] for bug fixes
  • [feat] for new features
  • [docs] for documentation updates
  • [style] for style or formatting changes
  • [refactor] for code reorganizations without feature changes

Real-Life Examples of Good Commit Messages

To illustrate the difference between a bad and a good commit message, here are a few examples:

  • Bad: "fix"
  • Good: [fix] Fixed login page bug

  • Bad: "update"

  • Good: [feat] Added share button to articles page

These examples clearly show the difference. The first example doesn’t tell much about what was fixed, while the second explicitly explains which bug was fixed. Similarly, for adding a feature, the good message explains exactly what was added.


Bonus: Tips for Writing Clear Commits

Here are some best practices for writing effective commit messages:

  • Be clear and concise: Your message should describe exactly what you did without being too long.
  • Use the imperative form: Write your commit messages as commands. Example: "Add search functionality" instead of "Adding search functionality."
  • Ask yourself this question: "What does this commit change in the project?" If your message answers this clearly, you're on the right track.

Recap

Good commit messages help:

  • Keep a clean and understandable Git history.
  • Improve team collaboration.
  • Make project maintenance easier in the long run.

Conclusion

Now that you know how to structure your commit messages, it's time to put these tips into practice! Start writing clear and meaningful commit messages today. And if you've seen funny or confusing commit messages, share them in the comments!

Don’t forget to share this article with other developers and follow for more development tips!

Top comments (0)