What are Semantic Commits?

August 1, 2023 Avishka Devinda

What are Semantic Commit Messages

As a developer, it's important to keep track of the changes you make to your codebase. One way to do this is by using commit messages, which are short descriptions of the changes made in each commit. While it's important to have commit messages that accurately describe the changes made, it's also important to use a consistent format for these messages. This is where semantic commit messages come in.

Semantic commit messages follow a specific format that allows developers to easily understand the purpose of each commit at a glance. This can be especially useful when working on a team or when reviewing code changes made by others.

Here's an example of a semantic commit message:

feat: add hat wobble
^--^  ^------------^
|     |
|     +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.

In this example, the commit message begins with the type of change being made (feat), followed by a colon and a brief summary of the change in present tense. The type of change can be one of several options, including:

  • fix: a bug fix for the user, not a fix to a build script
  • docs: changes to the documentation
  • style: formatting, missing semi-colons, etc; no production code change
  • refactor: refactoring production code, e.g. renaming a variable
  • test: adding missing tests, refactoring tests; no production code change
  • chore: updating grunt tasks, etc; no production code change

Using semantic commit messages can help developers better understand the changes made to a codebase and make it easier to track progress and identify issues. It's a simple change that can have a big impact on the maintainability and organization of a project.

How to Use Semantic Commit Messages

Using semantic commit messages is easy. Simply follow the format outlined above when writing your commit messages. Start with the type of change being made, followed by a colon and a brief summary of the change in present tense. Here are a few tips to keep in mind when using semantic commit messages:

  • Keep the summary brief but informative. Aim for around 50 characters or less.
  • Use present tense when writing the summary. For example, "add hat wobble" instead of "added hat wobble."
  • Choose the appropriate type of change for each commit. If you're not sure which type to use, take a moment to consider the purpose of the commit.

By following these guidelines, you can create commit messages that are clear, concise, and easy to understand. This can help you and your team track changes to the codebase more effectively and make it easier to collaborate on projects.