How to use Commitizen
Editor to share with you how to use Commitizen, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
First, if you want to do good work, you must first sharpen its tools.
A large number of code submissions will inevitably produce a large number of commit log, and each commit is a phased Ending, which should record the things completed at this stage and concerns, as detailed and specific as possible; and provide more historical information to facilitate quick browsing; you can filter some commit (such as document changes) to facilitate quick information search; you can generate Change log directly from commit. So the format of log is the key, and [Commitizen] (https://www.npmjs.com/package/commitizen)) can solve these problems perfectly.
What is Commitizen?
Is a tool for formatting commit message. Its installation requires [NPM] (https://www.npmjs.com/package/npm) support, NPM is Node.js 's package management tool, so first install [node.js] (https://nodejs.org/en/download/)), download the package of the corresponding system, and install it.
III. Commitizen installation
Npm install-g commitizen
Installing changelog is a tool for generating changelog
Npm install-g conventional-changelognpm install-g conventional-changelog-cli
Execution
Npm ls-g-depth=0
Verify whether the above two tools are installed successfully, and the results are as follows, indicating success:
/ usr/local/lib ├── commitizen@2.9.6 ├── conventional-changelog@1.1.7 ├── conventional-changelog-cli@1.3.5 └── npm@5.5.1
Then, run the following command to support Angular's Commit message format.
Commitizen init cz-conventional-changelog-- save--save-exact
Note, however, that because the commitizen tool is based on Node.js, and there is no package.json file in our iOS project directory, an error will be reported:
Npm WARN saveError ENOENT: no such file or directory, open'/ Users/Elite/package.json'npm WARN enoent ENOENT: no such file or directory, open'/ Users/Elite/package.json'
For this error, create an empty package.json file, then go to the project directory, and execute
Npm init-yes
The package.json of the project corresponding to the project is generated, and the contents of the package.json generated under the project directory are written to the self-built package.json (/ User/Elite/package.json). If there are multiple projects, the package.json content generated by each project is written to the package.json. The following is my configuration (/ User/Elite/package.json):
[{"name": "salary", "version": "1.0.0", "description": "> v1.0 covers the basic salary, reward salary and penalty salary of all teachers (non-secondary education)." , "main": "index.js", "scripts": {"test": "echo\" Error: no test specified\ "& & exit 1"}, "repository": {"type": "git", "url": "git@***.***.com:erp/salary.git"}, "keywords": [], "author": "," license ":" ISC " "devDependencies": {"cz-conventional-changelog": "^ 2.1.0"}, "config": {"commitizen": {"path": ". / node_modules/cz-conventional-changelog"}}, "dependencies": {}}, {"name": "ats", "version": "1.0.0", "description": "composer.json composer configure vendor third-party library" "main": "index.js", "directories": {"test": "tests"}, "scripts": {"test": "echo\" Error: no test specified\ "& exit 1"}, "repository": {"type": "git", "url": "git@***.***.com:ats/ats.git"}, "keywords": [], "author": "" "license": "ISC"}]
Then go to the project directory you want to operate and execute
Conventional-changelog-p angular-I CHANGELOG.md-s
At this point, there are more CHANGELOG.md files in the project, indicating that the Change log generation is successful. In the future, whenever you use the git commit command, it will be changed to git cz, and then an option will appear to generate a Commit Message that conforms to the format. Examples are as follows:
? Select the type of change that you're committing: (Use arrow keys) ❯ feat: A new feature fix: A bug fix docs: Documentation only changes style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) refactor: A code change that neither fixes a bug nor adds a feature perf: A code change that improves performance test: Adding missing tests or correcting existing tests
Then execute the operation to generate change log. If you end up with an error like this:
Error: Could not resolve / Users/Elite/web/node_modules/cz-conventional-changelog. Cannot find module'/ Users/Elite/web/node_modules/cz-conventional-changelog'
Just make a soft connection:
Ln-s / Users/Elite/node_modules / Users/Elite/web/node_modules
Of course, you can install plugin: Git Commit Template under the IDE tool.
The above is all the contents of this article "how to use Commitizen". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!