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

Do you know how to use Vue to take screenshots of web pages?

Table of contents 1. Install html2Canvas 2. Intro...

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

Complete steps to achieve high availability with nginx combined with keepalived

Preface In order to meet the high availability of...

Docker automated build Automated Build implementation process diagram

Automated build means using Docker Hub to connect...

HTML6 implements folding menu and accordion menu example code

The main part of the page: <body> <ul id...

Docker-compose installation db2 database operation

It is troublesome to install the db2 database dir...

JavaScript implementation of the Game of Life

Table of contents Concept Introduction Logical ru...

How to set mysql permissions using phpmyadmin

Table of contents Step 1: Log in as root user. St...

Introduction to using data URI scheme to embed images in web pages

The data URI scheme allows us to include data in a...

Detailed example of using js fetch asynchronous request

Table of contents Understanding Asynchrony fetch(...

How to set background color and transparency in Vue

Background color and transparency settings As sho...

Detailed explanation of how to copy and backup docker container data

Here we take the Jenkins container as an example ...