1. Plug-ins used

The commit format is Commitizen & CZ-Conventional – Changelog

  • Commitizen /cz-cli: use git cz instead of git commit to generate a compliant commit message.
  • Cz-xconventional – Changelog: as the Adapter designated by Commitizen, commitizen helps us generate commit messages according to the specified specifications.

Verify commit format: @commitLint/config-Conventional & @commitlint/cli & husky

  • Commitlint: Allows us to lint commit messages and reject the commitlint if the commitlint does not comply with the specified specification.
  • Commitlint /config-conventional: indicates the configuration used as verification.
  • Husky: Provide Git hook.

2. Configuration procedure

Standardize the COMMIT format

Step1: NPM install -g commitizen

Step2: Project-level installation: NPM CZ-Conventional – Changelog

Step3: configure in package.json:

"config": {
   "commitizen": {
        "path""node_modules/cz-conventional-changelog"}}Copy the code

Run git add. And then git cz. If the following information is displayed, the configuration is successful

Verify commit format

Step1: project-level installation: NPM I -d @commitlint/config-conventional @commitlint/cli

Step2: Create a configuration file commitlint.config.js in the project directory and write:

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

Step3: The best way to verify commit message with Husky is to combine Git hook, so Husky: NPM I-D Husky is needed

Step4: Look at the Husky version

If Husky <5.0.0:

Configure in package.json:

"husky": {
    "hooks": {
      "commit-msg": "commitlint -e $GIT_PARAMS"
   }
},
Copy the code
  • Husky version >=5.0.0:

Execute NPX husky install to install git hooks

Execute NPX husky add. husky/commit-msg ‘NPX commitlint –edit $1’ to enable commit-msg hook for commitlint

(Note that single quotation marks are used instead of double quotation marks)

1. After the installation and configuration are successful, run git add. And then run git commit -m “feat: test”.

Ps 1: It is possible to have husKY installation prompts “Lint-staged Command is not found” :

Solutions:

Run NPM install Lint-staged –save-dev and configure it in package.json:

"lint-staged": {
    "*": [
        "mew fix --replace"
    ]
},
Copy the code

Supplement 2: If HusKY does not work:

Solutions:

Run git config –list to check your Git configuration

Check whether a hooksPath exists and remove it if so

Git config –unset core.hookspath

3. Use method

Method 1: Run git cz to enter commit MSG, commit commit, and verify

Git commit -m “MSG”

  • Not conforming to specification, submission failed:

  • Submission successful:

Method 3: Use SourceTree, commit and verify

Note: You must open SourceTree on the command line for git hook to take effect

Open the Iterm, input: open – n/Applications/Sourcetree. Open Sourcetree app, then normal operation.

  • If the submission fails, the result is as follows: