Previously on
Every time Git commits code, write a Commit message, otherwise Commit is not allowed.
git commit -m "init"
Copy the code
In general, the Commit message should be clear and state the purpose of the commit.
The benefits of normalizing a COMMIT Message
- Provides more historical information for quick browsing;
- Certain commits, such as document changes, can be filtered to make it easy to find information quickly
- You can generate Change logs directly from commit
Commit Message format
One of the most popular and well-worked specifications in the industry is the Angular team specification, as follows:
< type > (< scope >) : < subject > / / short line < body > / / short line < footer >Copy the code
The three parts of the Commit message are Header, Body, and Footer. The Header is required, and the Body and Footer can be omitted.
Header
The Header section is a single line with three fields: Type (required), scope (optional), and subject (required).
-
Type: Indicates the type of commit. There are generally the following kinds:
Feat. Feat. Readme.md style (feat. Readme.md style) refactor (feat. Optimization related, such as improving performance, user experience, etc. Test: test cases, including unit tests and integration tests. Chore: Change the build process, or add dependency libraries, tools, etc.Copy the code
-
Scope: Specifies the scope of the commit impact, such as the data layer, control layer, view layer, and so on, depending on the project;
-
Subject: Short description of the commit destination
Body
The detailed description of the commit modification can be divided into multiple lines. As follows:
# body: 72 characters, including: # * Why do I need this change? # * How to solve this problem? Are there any other side effects to the project? Number of submissionsCopy the code
Footer
The Footer section is only used in two cases:
- Some notes, usually
BREAKING CHANGE
(current code is not compatible with previous version); - Fixed bug(close Issue) link.
Four, Commitizen
Github.com/commitizen/…
The installation
npm install -g commitizen
Copy the code
In the project directory, run the following command to support Angular’s Commit Message format
commitizen init cz-conventional-changelog --save-dev --save-exact
Copy the code
Note that if you want to force installation on top of an old adapter, you can apply the –force parameter. For more information on this, simply run commitizen Help
The command above does three things for you:
- The installation
cz-conventional-changelog
Adapter NPM module; - Save it to
package.json
‘sdependencies
ordevDependencies
; - will
config.commitizen
The key is added to the root of the file,package.json
As follows:
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
Copy the code
As follows:
Git cz: git cz: git cz: git cz: git cz: git cz: git cz
Use husKY + CommitLint to check that the Commit message complies with the specification
Husky 6. X Upgrade Guide – Digging For Gold
Generate Change log
Github.com/conventiona…
If all your Commits are in Angular format, the Change log can be automatically generated by the script when you release a new version.
The generated document consists of the following three parts:
- New features
- Bug fixes
- Breaking changes
Convention-changelog is a tool for generating Change log. Run the following command:
npm install -g conventional-changelog-cli
cd my-project
conventional-changelog -p angular -i CHANGELOG.md -s
Copy the code
By configuring this command into scripts, you can generate Changelog by running the NPM run Changelog command:
{
"scripts": {
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
}
}
Copy the code
NPM version (see documentation readme.md)
{
"scripts": {
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
}
}
Copy the code
(Optional) Produce a commit with an icon with git-cz
Github.com/streamich/g…
The above can basically meet our standardized use, git-cz beautification submission.
npm install -g git-cz
commitizen init git-cz --save-dev --save-exact
Copy the code
If an error is reported, follow the error solution. Add –force after the command.