2
头图

Overview

Every time we submit the code, we need to add a description for the content we modified this time, for example:

git commit -m "Initial commit";
git commit -m "修复了一些已知问题。";
git commit -m "增加了新特性。";

But in fact, some commit messages are strange, such as the following:

image.png
A commit should accurately state the purpose and modification of the commit, such as:

git commit -m "chore: upgrade org.bouncycastle:bcprov-jdk15on from 1.69 to 1.70";
git commit -m "perf: optimize the code on global zookeeper";
git commit -m "docs(readme): fix typo";

This way of writing comes from the Angular team’s Git contractual commit. You can read their specifications from the following link:

  1. Git Commit Message Conventions
  2. Understanding Semantic Commit Messages Using Git and Angular
  3. Angular submission information specification
  4. agreed to submit

Use contract submission

Conventional submission has agreed on the format of the commit message, as shown below:

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LIKE>
<footer>

The submission message is composed of header, body, and footer. Let's introduce them in detail.

Message header

The header consists of type, scope, and subject. In the complete agreed submission format, the part it occupies is:

<type>(<scope>): <subject>

The meaning represented is:

  • type: Required, the type of this submission.
  • scope: Optional, indicating the scope of impact of this submission.
  • subject: Required, a brief description of this submission.

    type

    The value of type must be one of the following list:

  • build/chore👷‍♀️: Used to build system (including scripts, configuration or tools) and dependencies.
  • ci: Configuration files, script files, configurations or tools related to system continuous integration and continuous deployment.
  • docs📝: Used to identify changes in project-related documents.
  • feat✨: Used to identify new features.
  • fix🐛: Used to identify bug fixes.
  • perf⚡️: Used to identify performance improvements.
  • refactor: Used to identify code refactoring, neither adding new features nor fixing errors-such as deleting redundant code, simplifying code, renaming variables, etc.
  • style: Used to mark code formatting, code style modulation, and fix checkstyle and other issues.
  • tets: Used to mark test-related changes, modify existing tests or add new tests.
  • revert: The user branch is rolled back.
    Illustrate with a picture:
    image.png
scope

The scope can be divided according to modules and packages, and the specific use can be based on the specifications established by the team, for example:

git commit -m "feat(logger): support JSONL log output format";
git commit -m "feat(dao): add global controller excepiton handler";
git commit -m "feat(api): add reqeust interceptor"
subject

For a brief description of this submission, there are the following guidelines:

  1. The first letter is lowercase.
  2. Does not end with a period.
Example

The header is just the first line of the commit message. You can use git commit -m to complete this submission, for example:

git commit -m "chore(pom.xml): upgrade jackson-databind from 2.10.1 to 2.11.4"

Type submitted in the above example is chore , followed in () the middle of the range specified in the scope or impact modified file is pom.xml , then keep an English : and a space is our subject. It should be noted that : is in English. After : , a space and subject are needed as a partition.

As mentioned before, scope is optional. If we ignore scope, then the above example can be changed to:

git commit -m "chore: upgrade jackson-databind from 2.10.1 to 2.11.4"

Message body

The body is optional, you can introduce the reason for the modification and the detailed content:

fix(users): remove getFriends API endpoint

In accordance with new privacy policy, remove the getFriends API endpoint. 
(The endpoint will continue to exist for a while and return a deprecation notice)

It should be noted that there needs to be a blank line before header and body.

Message footer

footer is also optional. If this submission is to modify issue , you can quote issue in the footer, for example:

fix(users): remove getFriends API endpoint

In accordance with new privacy policy, remove the getFriends API endpoint. 
(The endpoint will continue to exist for a while and return a deprecation notice)

Implements #2105

A blank line is also required between footer and body.

The benefits

Generate changelog

image.png

Browsing records

We can browse the submission records of the specified type, for example, display the submission records of feat, fix, and perf:

git log --oneline --grep "^feat|^fix|^perf"

commit message emoji

Adding emoji to the commit message will make our submission more interesting and easy to browse, for example:

image.png
You can find the emoji corresponding to the commit message type at the following link:

  1. https://gitmoji.dev/
  2. commit-message-emoji
  3. GitCommitEmoji
  4. why-i-use-emojis-in-my-git-commits
  5. how-to-use-emoji-in-your-commit-message

If you are using the VS Code editor or your package manager is npm, then you can also find the corresponding plug-in:

  1. npm-gitmoji-cli
  2. gitmoji-vscode

async_wait
10 声望3 粉丝