.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}

CommitMsg

Git submission specification

background

As an open source distributed version control system, Git has become the most popular project code version management tool at present. In other words, teams need to have certain rules and norms, so as to give better play to team efficiency. If you are familiar with Git, you must write a Commit message every time you Commit your code. Otherwise, you are not allowed to Commit. Git does not impose any restrictions on the information you Commit. The Angular specification is by far the most widely written, reasonable and systematic. This article looks at two ways to use the Angular specification.

Method 1, triggered by hooks based on the project (this method is used by our team)

The advantage of this approach is that anyone who wants to commit to this project must follow the specification or not commit.

  1. Install required dependencies,npm i --save-dev husky chalk;
  2. Create a new folder in the root directory of your project.github(name optional), this folder is dedicated to Github related stuff;
  3. Create a new folder in the previous stepnodeThe script fileverifyCommitMsg(name optional);
  4. In the script file from the previous step, write the following code:
#! /bin/env node const chalk = require('chalk'); const msgPath = process.env.HUSKY_GIT_PARAMS; if (! msgPath) { console.error(chalk.red(`process.env.HUSKY_GIT_PARAMS can't be ${msgPath},please check`)); process.exit(1); } console.log('HUSKY_GIT_PARAMS: ', msgPath); const msg = require('fs') .readFileSync(msgPath, 'utf-8') .trim(); console.log(msg); const commitRE = /^(revert: )? (feat|fix|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))? : {1, 50} /; if (! commitRE.test(msg) && ! /merge/ig.test(msg)) { console.log(); console.error( ` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(`invalid commit message format.`)}\n\n` + chalk.red( ` Proper commit message format is required for automated changelog generation. Examples:\n\n` ) + ` ${chalk.green(`feat(compiler): add 'comments' option`)}\n` + ` ${chalk.green(`fix(v-model): handle events on blur (close #28)`)}\n\n` + chalk.red(` See .github/COMMIT_CONVENTION.md for more details.\n`) // chalk.red(` You can also use ${chalk.cyan(`npm run commit`)} to interactively generate a commit message.\n`) ); process.exit(1); }Copy the code
  1. inpackage.jsonAdd/modify hooks as follows:
."husky": {
  "hooks": {
    "commit-msg": "node .github/verifyCommitMsg"}},...Copy the code

This allows the commit information to be checked every time the commit is committed and given a warning if it does not conform to the specification. Such as:

Method two, based on NPM dependency plug-in

The advantage of this approach is that submission is more personal.

  1. Global installation dependencies,npm i -g commitizen
  2. Initialize the adapter,commitizen init cz-conventional-changelog --save-dev --save-exact
  3. withgit czCommand instead ofgit commit

Such as:

===🧐🧐