Commitizen for contributors
Installing the command line tool
- ``` shell
- npm install -g commitizen
- ```
Using the command line tool
If your repo is Commitizen friendly:
- ``` shell
- npx cz
- ```
- ``` json
- ...
- "scripts": {
- "commit": "cz"
- }
- ```

If your repo is NOT Commitizen friendly:
Making your repo Commitizen friendly
- ``` shell
- npm install commitizen -g
- ```
- ``` shell
- # npm
- commitizen init cz-conventional-changelog --save-dev --save-exact
- # yarn
- commitizen init cz-conventional-changelog --yarn --dev --exact
- # pnpm
- commitizen init cz-conventional-changelog --pnpm --save-dev --save-exact
- ```
- ``` json
- ...
- "config": {
- "commitizen": {
- "path": "cz-conventional-changelog"
- }
- }
- ```
- ``` json
- {
- "path": "cz-conventional-changelog"
- }
- ```
Optional: Install and run Commitizen locally
- ``` sh
- npx commitizen init cz-conventional-changelog --save-dev --save-exact
- ```
- ``` json
- ...
- "scripts": {
- "commit": "cz"
- }
- ```
NOTE:If you are using precommit hooks thanks to something like husky, you will need to name your script something other than "commit" (e.g. "cm": "cz" ). The reason is because npm scripts has a "feature" where it automatically runs scripts with the name prexxxwhere xxxis the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit", and the workaround is to prevent the npm-triggered precommitscript.
Optional: Running Commitizen on git commit
NOTE:This example assumes that the project has been set up to use Commitizen locally.
Traditional git hooks
- ``` shell
- #!/bin/bash
- exec < /dev/tty && node_modules/.bin/cz --hook || true
- ```
Husky
- ``` json
- "husky": {
- "hooks": {
- "prepare-commit-msg": "exec < /dev/tty && npx cz --hook || true"
- }
- }
- ```
Why exec < /dev/tty ?By default, git hooks are not interactive. This command allows the user to use their terminal to interact with Commitizen during the hook.
Congratulations! Your repo is Commitizen friendly. Time to flaunt it!
- ``` sh
- [](http://commitizen.github.io/cz-cli/)
- ```
Conventional commit messages as a global utility
- ``` shell
- npm install -g commitizen
- ```
- ``` shell
- npm install -g cz-conventional-changelog
- ```
- ``` shell
- echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
- ```
If your repository is a Node.js project, making it Commitizen friendly is super easy.
Commitizen for multi-repo projects
1. Create your own entry point script
- ``` js
- // my-cli.js
- #!/usr/bin/env node
- "use strict";
- const path = require('path');
- const bootstrap = require('commitizen/dist/cli/git-cz').bootstrap;
- bootstrap({
- cliPath: path.join(__dirname, '../../node_modules/commitizen'),
- // this is new
- config: {
- "path": "cz-conventional-changelog"
- }
- });
- ```
2. Add the script to your package.json file
- ``` json
- // package.json
- {
- "name": "company-commit",
- "bin": "./my-cli.js",
- "dependencies": {
- "commitizen": "^2.7.6",
- "cz-conventional-changelog": "^1.1.5"
- }
- }
- ```
3. Publish it to npm and use it!
- ``` shell
- npm install --save-dev company-commit
- ./node_modules/.bin/company-commit
- ```