Patterns

Git Commit Message

Writing Commit Messages

Git commit message follows conventions like Conventional Commits.

Introduction to Git Commit Messages

Git commit messages are essential for collaborating with others and managing your code base. They provide a historical record of changes, help others understand the context of changes, and can even automate release and deployment processes. Following conventions such as Conventional Commits can make your commit history more readable and useful.

Why Use Conventional Commits?

Conventional Commits is a specification for writing commit messages that are easy to understand and tool-friendly. They facilitate automation and improve the readability of the commit history. Conventional Commits follow a pattern that includes a type, an optional scope, and a description.

  • Type: Describes the intent of the change (e.g., feat, fix).
  • Scope: Optional, specifies the section of the code affected (e.g., ui, api).
  • Description: A brief summary of the changes.

Structure of a Conventional Commit

A Conventional Commit message is structured as follows:

Types of Commits

Here are some common types of commits:

  • feat: A new feature.
  • fix: A bug fix.
  • docs: Documentation changes.
  • style: Code style changes (e.g., formatting).
  • refactor: Code changes that neither fix a bug nor add a feature.
  • test: Adding or updating tests.
  • chore: Changes to the build process or auxiliary tools and libraries.

Example of a Conventional Commit Message

Let's look at an example of a conventional commit message for a bug fix in the user interface:

Best Practices for Writing Commit Messages

Here are some best practices to follow when writing commit messages:

  • Keep it concise: The subject line should be clear and to the point, ideally under 50 characters.
  • Use the imperative mood: Write your commit message as if you're giving a command (e.g., "Add feature" instead of "Added feature").
  • Separate subject from body with a blank line: This helps in maintaining a clean and readable commit history.
Previous
Subtree