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

Detailed tutorial on installing Python 3 virtual environment in Ubuntu 20.04

The following are all performed on my virtual mac...

100 ways to change the color of an image using CSS (worth collecting)

Preface “When it comes to image processing, we of...

Detailed explanation of MySQL three-value logic and NULL

Table of contents What is NULL Two kinds of NULL ...

Docker Tutorial: Using Containers (Simple Example)

If you’re new to Docker, take a look at some of t...

Implementation of multi-port mapping of nginx reverse proxy

Code Explanation 1.1 http:www.baidu.test.com defa...

MySQL 8.0.21 installation and configuration method graphic tutorial

Record the installation and configuration method ...

Practical record of vue using echarts word cloud chart

echarts word cloud is an extension of echarts htt...

How to enable the slow query log function in MySQL

The MySQL slow query log is very useful for track...

Small problem with the spacing between label and input in Google Browser

Code first, then text Copy code The code is as fol...

How to completely uninstall mysql under CentOS

This article records the complete uninstallation ...

HTML cellpadding and cellspacing attributes explained in pictures

Cell -- the content of the table Cell margin (tabl...

Detailed explanation of common operations of Docker images and containers

Image Accelerator Sometimes it is difficult to pu...