Your Commit Messages Suck ๐Ÿ‘Ž; Here's How to Fix It

Photo by Yancy Min on Unsplash

Your Commit Messages Suck ๐Ÿ‘Ž; Here's How to Fix It

Elevate Your Development Workflow with Crystal-Clear Semantic Commit Messages

ยท

3 min read

Hey there, fellow developers!

Today, let's talk about one of the most overlooked yet crucial aspects of collaborative coding โ€“ commit messages.

We've all been guilty of hasty, unclear commit messages, but fear not! In this article, we'll delve into the world of semantic commit messages and learn how they can significantly improve your development workflow.

The Anatomy of a Semantic Commit Message

A semantic commit message follows a specific structure:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Let's break it down:

<type>: Describes the purpose of the commit. It can be one of the following:

  • feat: Introducing a new feature for the user.

  • fix: Resolving a bug for the user.

  • docs: Documentation changes.

  • style: Code formatting, missing semicolons, etc.

  • refactor: Refactoring production code.

  • test: Adding or refactoring tests.

  • chore: General maintenance tasks.

[optional scope]: Describes the module or component the commit affects.

<description>: Uses imperative, present tense. Clearly states what the commit does.

[optional body]: Provides additional context, if needed. Describes the motivation for the change and contrasts with the previous behavior.

[optional footer(s)]: Contains references to issues and notes on breaking changes.

Example for <type> and <scope>

feat(init): add user authentication

style(web-server): enforce consistent code formatting

chore(config): update dependencies

Examples of semantic commit messages

  1. Adding a New Feature:
feat(user-auth): implement OAuth2 login
  1. Fixing a Bug:
fix(validation): resolve issue with form not validating email input
  1. Documentation Update:
docs(readme): update installation instructions
  1. Code Formatting:
style(codebase): enforce consistent indentation
  1. Refactoring Code:
refactor(api): rename variable for clarity
  1. Adding Tests:
test(auth): add unit tests for login functionality
  1. General Maintenance Task:
chore(dependencies): update package versions

Writing Commit Messages โ€“ Best Practices

  1. Be Clear and Concise: A developer should understand the purpose of your commit by reading the message.

  2. Present Tense: Use imperative, and present tense. For example, "add feature" instead of "added feature."

  3. Provide Context: Include a brief explanation of why the change is necessary.

  4. Reference Issues: If your commit resolves an issue, mention it in the footer using "Closes #issueNumber."

  5. Breaking Changes: Clearly document breaking changes in the footer using the "BREAKING CHANGE:" keyword, along with a description, justification, and migration notes.

Why bother about commit messages

Semantic commit messages bring clarity and structure to your version control history. They make it easier to track changes, understand the project's evolution, and collaborate effectively.

In the end, take the time to craft meaningful commit messages. Your future self and your collaborators will thank you.

Read more here: karma-runner.github.io/1.0/dev/git-commit-m..conventionalcommits.org/en/v1.0.0

Happy coding! ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿš€

DEVDESIIGNN from Eyes on Tech.

ย