GIT — Conventional Commits

Ahoy there, matey! May your day be as bright as a sunflower on a summer’s day! Let’s have a short and sweet discussion about ways to commit to GIT.

In simple words, Conventional Commits are a set of guidelines for structuring and formatting commit messages in a consistent and standardized way. This specification aims to make it easier to read and understand commit messages, particularly in the context of automated tooling and workflows for GIT. It provides a set of rules for writing commit messages that allow both humans and machines to understand what changes were made and why. Let’s give one example:

feat(feature_1): add feature 1

In this example, “feat” is the type of commit, “feature_1” is the scope, and "add feature 1" is the description. Let’s take a closer look at each part of the message.

TYPES OF COMMIT

The type of the commit indicates the nature of the change that was made. The types are defined in the Conventional Commits specification and include:

  1. feat: A new feature
  2. fix: A bug fix
  3. docs: Documentation changes
  4. style: Changes that do not affect the meaning of the code (e.g., formatting)
  5. refactor: Code changes that neither fix a bug nor add a feature
  6. perf: Changes that improve performance
  7. test: Adding missing tests or correcting existing tests
  8. build: Changes to the build system or external dependencies
  9. ci: Changes to the continuous integration (CI) system or configuration files
  10. chore: Other changes that do not modify src or test files

Why Use Conventional Commits?

There are many benefits for the developers and the team when we use conventional commits. Some of them are:

  1. Consistent commit messages — With the help of a standard format for commit messages, everyone on the team can understand what changes were made and why, even if they didn’t write the code themselves.

  2. Better documentation — Commit messages are a form of documentation, and conventional commits make it easier to search through commit history to understand how the codebase has evolved over time.

  3. Automated releases — Many automated release tools, such as semantic-release, use conventional commits to determine what version number to assign to a release. By following the Conventional Commits specification, you can automate your release process and avoid manual versioning.

Syntax Of Conventional Commits.

To use conventional commits, you need to follow a structure or format. Here’s an example of how to write a conventional commit:

<type>(<scope>): <description>

[optional body]

[optional footer]

Here, the type, scope, and description are required. The body and footer are optional and can provide additional information about the change. Here's an example of a more complex commit message that includes a body and footer:

feat(feature_2): add feature 2

This section is about the description, where you can describe your feature a little longer.

Closes #1234

So, this is about conventional commits. I hope you will start to use commits in a structured, formatted way from now on.

Happy Coding!!!