Skip to content

Commit c3c533f

Browse files
authored
feat: use cz as binary name (#767)
While still support the old git-cz binary name. Also improve the documentation. Closes #761
1 parent f7257f8 commit c3c533f

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

README.md

+12-11
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ npm install -g commitizen
2222

2323
### If your repo is [Commitizen-friendly]:
2424

25-
Simply use `git cz` instead of `git commit` when committing.
25+
Simply use `git cz` or just `cz` instead of `git commit` when committing. You can also use `git-cz`, which is an alias for `cz`.
2626

2727
_Alternatively_, if you are using **NPM 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) instead of installing globally:
2828

2929
```
30-
npx git-cz
30+
npx cz
3131
```
3232

3333
or as an npm script:
3434

3535
```json
3636
...
3737
"scripts": {
38-
"commit": "npx git-cz"
38+
"commit": "cz"
3939
}
4040
```
4141

@@ -45,7 +45,7 @@ When you're working in a Commitizen friendly repository, you'll be prompted to f
4545

4646
### If your repo is NOT Commitizen friendly:
4747

48-
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx git-cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)
48+
If you're **not** working in a Commitizen friendly repository, then `git cz` will work just the same as `git commit` but `npx cz` will use the [streamich/git-cz](https://github.com/streamich/git-cz) adapter. To fix this, you need to first [make your repo Commitizen-friendly](#making-your-repo-commitizen-friendly)
4949

5050
## Making your repo Commitizen-friendly
5151

@@ -118,7 +118,7 @@ On **NPM 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-np
118118
npx commitizen init cz-conventional-changelog --save-dev --save-exact
119119
```
120120

121-
For **previous versions of NPM (< 5.2)** you can execute `./node_modules/.bin/commitizen` or `./node_modules/.bin/git-cz` in order to actually use the commands.
121+
For **previous versions of NPM (< 5.2)** you can execute `./node_modules/.bin/commitizen` or `./node_modules/.bin/cz` in order to actually use the commands.
122122

123123
You can then initialize the conventional changelog adapter using: `./node_modules/.bin/commitizen init cz-conventional-changelog --save-dev --save-exact`
124124

@@ -127,13 +127,15 @@ And you can then add some nice npm run scripts in your package.json pointing to
127127
```json
128128
...
129129
"scripts": {
130-
"commit": "git-cz"
130+
"commit": "cz"
131131
}
132132
```
133133

134134
This will be more convenient for your users because then if they want to do a commit, all they need to do is run `npm run commit` and they will get the prompts needed to start a commit!
135135

136-
> **NOTE:** if you are using `precommit` hooks thanks to something like `husky`, you will need to name your script some thing other than "commit" (e.g. "cm": "git-cz"). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name _prexxx_ where _xxx_ is the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit," and the work around is to prevent the npm-triggered _precommit_ script.
136+
> **NOTE:** if you are using `precommit` hooks thanks to something like [`husky`](https://www.npmjs.com/package/husky), you will need to name your script some thing other than `"commit"`
137+
> (e.g. `"cm": "cz"`). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name _prexxx_ where _xxx_ is the name of another script. In essence,
138+
> npm and husky will run `"precommit"` scripts twice if you name the script `"commit"`, and the work around is to prevent the npm-triggered _precommit_ script.
137139
138140
#### Optional: Running Commitizen on `git commit`
139141

@@ -150,7 +152,7 @@ Update `.git/hooks/prepare-commit-msg` with the following code:
150152

151153
```
152154
#!/bin/bash
153-
exec < /dev/tty && node_modules/.bin/git-cz --hook || true
155+
exec < /dev/tty && node_modules/.bin/cz --hook || true
154156
```
155157

156158
##### Husky
@@ -283,11 +285,10 @@ As of version 2.7.1, you may attempt to retry the last commit using the `git cz
283285

284286
Please note that the retry cache may be cleared when upgrading commitizen versions, upgrading adapters, or if you delete the `commitizen.json` file in your home or temp directory. Additionally, the commit cache uses the filesystem path of the repo, so if you move a repo or change its path, you will not be able to retry a commit. This is an edge case, but might be confusing if you have scenarios where you are moving folders that contain repos.
285287

286-
It is important to note that if you are running `git-cz` from a npm script (let's say it is called `commit`) you will need to do one of the following:
288+
It is important to note that if you are running `cz` from a npm script (let's say it is called `commit`) you will need to do one of the following:
287289

288290
- Pass `-- --retry` as an argument for your script. i.e: `npm run commit -- --retry`
289-
- Use [npm-run](https://www.npmjs.com/package/npm-run) to find and call git-cz executable directly. i.e: `npm-run git-cz --retry`
290-
- Use [npm-quick-run](https://www.npmjs.com/package/npm-quick-run) i.e: `nr commit --retry` or just `nr c --retry` (which will run all scripts that starts with the letter 'c')
291+
- Use [npx](https://www.npmjs.com/package/npx) to find and call `cz` executable directly. i.e: `npx cz --retry`
291292

292293
Note that the last two options **do not** require you to pass `--` before the args but the first **does**.
293294

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"url": "https://github.com/commitizen/cz-cli/issues"
4242
},
4343
"bin": {
44+
"cz": "./bin/git-cz",
4445
"git-cz": "./bin/git-cz",
4546
"commitizen": "./bin/commitizen"
4647
},

src/cli/commitizen.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@ function bootstrap (environment = {}, argv = process.argv) {
3838
3939
Commitizen has two command line tools:
4040
41-
1) commitizen -- used for installing adapters into your project
42-
2) git-cz -- used for making commits according to convention
41+
1) cz -- used for making commits according to convention
4342
note: you can run 'git cz' if installed with -g
43+
2) git-cz -- alias for 'cz'
44+
3) commitizen -- used for installing adapters into your project
4445
4546
Generally if you're using someone else's repo and they've already set up an
4647
adapter, you're going to just be running:
4748
48-
git-cz
49+
cz
4950
5051
However, if you create a new repo and you want to make it easier for future
5152
contributors to follow your commit message conventions using commitizen then
@@ -71,13 +72,13 @@ function bootstrap (environment = {}, argv = process.argv) {
7172
--save-exact Install an exact version instead of a range
7273
--force Force install the adapter, even if a previous one exists.
7374
74-
2) git-cz <any regular git commit arguments>
75+
2) cz <any regular git commit arguments>
7576
7677
description: Runs the commitizen prompter, asking you questions so that you
7778
follow the commit conventions of the repository of the current
7879
directory.
7980
80-
note: git-cz may even be run as 'git cz' if installed with -g.
81+
note: cz may even be run as 'git cz' if installed with -g.
8182
8283
`);
8384
}

src/cli/strategies/git.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default git;
66
// or if debug is enabled then we do a strict check for a config file.
77
function git (rawGitArgs, environment) {
88
if (environment.debug === true) {
9-
console.error('COMMITIZEN DEBUG: No git-cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.');
9+
console.error('COMMITIZEN DEBUG: No cz friendly config was detected. I looked for .czrc, .cz.json, or czConfig in package.json.');
1010
} else {
1111
var vanillaGitArgs = ["commit"].concat(rawGitArgs);
1212

0 commit comments

Comments
 (0)