Detailed explanation of the significance of standard commit msg in JavaScript development

Detailed explanation of the significance of standard commit msg in JavaScript development

The significance of standard commit msg

Standardized and formatted commit messages allow us to better track the evolution of requirements, quickly find commits when rolling back, and at the very least make our repository appear more professional.

How does a team standardize commit msgs, by preaching or by documentation? Of course, it depends on tool generation and constraints. There are so many front-end wheels that this kind of tool is no problem.

  • commitizen question-and-answer style generation of commit msg format
  • commitlint check card control commit msg standardization

commitize

commitizen: simple commit conventions for internet citizens.

commitizen/cz-cli uses the git cz command it provides to replace the git commit command and generate a commit message that complies with the standard.

The default commit specification of commitizen is strictly stipulated by the angular team. If we want to customize it, we also need to cooperate with the Adapter. Here we use cz-customizable .

Let's go straight to the project-level configuration.

Perform commitizen configuration

Run npm install -D commitizen, npm install -D cz-customizable

Then configure the scripts and config fields in the package.json file

{
  "scripts": {
    "commit": "cz"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": ".cz-configrc.js"
    }
  }
}

Add .cz-configrc.js file

Try executing npm run commit in the root directory of the project.

Subsequent t npm run commit replaces git commit

commitlint

How to ensure that all members of the group use the npm run commit command? Of course, with tools.

Here we use commitlint, which has a similar function to eslint. Use git hooks to intercept commit msg that does not conform to the specifications.

Install Dependencies

npm install --save-dev @commitlint/{config-conventional,cli} 
npm install yorkie --save-dev

Add .commitlint.config.js file

Expand the open source configuration and then add some customized rules

Configuring git hooks

In order to intercept non-standard commit msg, you need to use git hooks commit-msg to automatically execute commitlint

"gitHooks": {
  "commit-msg": "commitlint -e $GIT_PARAMS"
}

Try entering a random commit msg and you will find it magical. The card control is effective.

Follow the above steps to standardize your team's commit msg.

To summarize:

Step 1: Install dependencies

npm install -D commitizen cz-customizable
npm install -D @commitlint/{config-conventional,cli}
npm install -D yorkie

Step 2: Add configuration file

Customized commitizen configuration file .cz-configrc.js , check standard .commitlint.config.js file

Configure package.json

{
  "scripts": {
    "commit": "cz"
  },
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-customizable"
    },
    "cz-customizable": {
      "config": ".cz-configrc.js"
    }
  },
  "gitHooks": {
    "commit-msg": "commitlint -e $GIT_PARAMS"
  }
}

The principle of git cz

If you are commitizing globally, you can also use the git cz command instead of npm run commit .

What is git cz ? git commands, and also commitizen commands.

By consulting the information, git cz is a custom git command generated by commitizen using git's file naming conventions.

Git follows the naming convention git-<subcmd> to automatically resolve subcommands from executable files in your PATH. These subcommands can be executed with git <subcmd> .

Let's look at the bin field of the commitizen repository package.json. It's really delicious, it's git's custom command

 "bin": {
    "cz": "./bin/git-cz",
    "git-cz": "./bin/git-cz",
    "commitizen": "./bin/commitizen"
  },

The above is the detailed content of the detailed explanation of the meaning of standard commit msg in the JavaScript development process. For more information about the meaning of development standard commit msg, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to submit verification specifications to git and automatically generate log files
  • Tips for using eslint and githooks to unify front-end styles
  • Vue front-end development specification arrangement (recommended)

<<:  Solution to the problem of the entire page not being centered when using margin:0 auto in HTML

>>:  20 Signposts on the Road to Becoming an Excellent UI (User Interface) Designer

Recommend

Summary of Mathematical Symbols in Unicode

There are many special symbols used in mathematic...

Docker Compose network settings explained

Basic Concepts By default, Compose creates a netw...

CSS horizontal centering and limiting the maximum width

A CSS layout and style question: how to balance h...

What are the differences between var let const in JavaScript

Table of contents 1. Repeated declaration 1.1 var...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

Detailed explanation of redundant and duplicate indexes in MySQL

MySQL allows you to create multiple indexes on th...

Use of Zabbix Api in Linux shell environment

You can call it directly in the Linux shell envir...

Steps to modify the MySQL database data file path under Linux

After installing the MySQL database using the rpm...

Perfect solution to Google Chrome autofill problem

In Google Chrome, after successful login, Google ...

Detailed explanation of desktop application using Vue3 and Electron

Table of contents Vue CLI builds a Vue project Vu...