Why standardize Git Commit messages

  • Problem identification code quickly
  • Commit establishes associations with code and associated PRDS and bugs.

How to write a normalized Git Commit Message

Use the Angular Git Commit Guidelines, which are widely used in the industry

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
Copy the code
  1. Type: Feat Fix Refactor Docs Style Test chore

  2. Scope: commit Specifies the scope of the impact, for example: route, Component, utils, build…

  3. Subject: Overview of commit

    • Start with a verb and use the present first-person tense such as’ change ‘rather than’ changed ‘or’ changes’
    • The first letter should be lowercase (Chinese can be used)
    • No sign at the end
  4. Body: commit The modified content can be divided into multiple lines

  5. Footer: Some notes, usually a link to BREAKING CHANGE or bug fixes

Reference steps for project usage

1.Com Mitizen: Replace your Git commit

Commitizen /cz-cli, we need to use the git cz command provided by it to replace our git commit command, to help us generate a compliant commit message.

In addition, we also need to specify an Adapter for Commitizen such as CZ-Conventional – Changelog (a preset that conforms to the Angular team specification). Have Commitizen help us generate a Commit message according to the specification we specified.

yarn add --dev commitizen cz-conventional-changelog
Copy the code

Package. json configuration:

"script": {... ."commit": "git-cz",},"config": {
    "commitizen": {
      "path": "node_modules/cz-conventional-changelog"}}Copy the code

If commitizen has been installed globally, git Cz or NPM run commit can be executed in the corresponding project

2.Com mitLint: Validates your message

Commitlint: Helps us commitlint commit messages. @commitlint/ config-Conventional is recommended for validation (conforming to Angular team specifications). Without further ado, follow directly:

yarn add --dev @commitlint/config-conventional @commitlint/cli
Copy the code

You also need to create the.commitlintrc.js configuration file in the project directory and write:

module.exports = {
  extends: [
    '@commitlint/config-conventional'].rules: {}};Copy the code

3. Combining with Husky

yarn add --dev husky
Copy the code

Add to package.json:

"husky": {
    "hooks": {... ."commit-msg": "commitlint -e $GIT_PARAMS"}},Copy the code

The resources

Gracefully Commit your Git Commit Message

Guide to writing Commit Message and Change log