You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-43Lines changed: 58 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,32 @@
1
-
### Commitizen for contributors
1
+
## Commitizen for contributors
2
+
2
3
When you commit with Commitizen, you'll be prompted to fill out any required commit fields at commit time. No more waiting until later for a git commit hook to run and reject your commit (though [that](https://github.com/kentcdodds/validate-commit-msg) can still be helpful). No more digging through [CONTRIBUTING.md](CONTRIBUTING.md) to find what the preferred format is. Get instant feedback on your commit message formatting and be prompted for required fields.
3
4
4
-
[](#backers)[](#sponsors)[](https://travis-ci.org/commitizen/cz-cli)[](https://dev.azure.com/commitizen/cz-cli/_build/latest?definitionId=2)
5
-
[](https://codecov.io/github/commitizen/cz-cli?branch=master)[](https://www.npmjs.com/package/commitizen)[](https://www.npmjs.com/package/commitizen)[](https://github.com/semantic-release/semantic-release)[](https://stackoverflow.com/tags/commitizen)
5
+
[](#backers)[](#sponsors)[](https://travis-ci.org/commitizen/cz-cli)[](https://dev.azure.com/commitizen/cz-cli/_build/latest?definitionId=2)
6
+
[](https://codecov.io/github/commitizen/cz-cli?branch=master)[](https://www.npmjs.com/package/commitizen)[](https://www.npmjs.com/package/commitizen)[](https://github.com/semantic-release/semantic-release)[](https://stackoverflow.com/tags/commitizen)
7
+
8
+
## Installing the command line tool
6
9
7
-
#### Installing the command line tool
8
10
Installation is as simple as running the following command (if you see `EACCES` error, reading [fixing npm permissions](https://docs.npmjs.com/getting-started/fixing-npm-permissions) may help):
9
11
10
12
```
11
13
npm install -g commitizen
12
14
```
13
15
14
-
#### Using the command line tool
15
-
Now, simply use `git cz` instead of `git commit` when committing.
16
+
## Using the command line tool
17
+
18
+
### If your repo is [Commitzen-Friendly]:
19
+
20
+
Simply use `git cz` instead of `git commit` when committing.
16
21
17
22
_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:
23
+
18
24
```
19
25
npx git-cz
20
26
```
27
+
21
28
or as an npm script:
29
+
22
30
```json
23
31
...
24
32
"scripts": {
@@ -30,9 +38,11 @@ When you're working in a Commitizen friendly repository, you'll be prompted to f
30
38
31
39
[](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)
32
40
33
-
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.
41
+
### If your repo is **NOT**[Commitzen-Friendly]:
42
+
43
+
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)
34
44
35
-
####Conventional commit messages as a global utility
45
+
## Conventional commit messages as a global utility
36
46
37
47
Install `commitizen` globally, if you have not already.
You are all set! Now `cd`into any `git` repository and use `git cz` instead of `git commit` and you will find the `commitizen` prompt.
56
66
57
-
Protip: You can use all the `git commit``options` with `git cz`, for example: `git cz -a`.
67
+
Protip: You can use all the `git commit``options` with `git cz`, for example: `git cz -a`.
68
+
69
+
> If your repository is a [nodejs](https://nodejs.org/en/) project, making it [Commitizen-friendly] is super easy.
58
70
59
-
>If your repository is a [nodejs](https://nodejs.org/en/) project, making it [Commitizen-friendly](#making-your-repo-commitizen-friendly) is super easy.
71
+
If your repository is already [Commitizen-friendly], the local `commitizen` adapter will be used, instead of globally installed one.
60
72
61
-
If your repository is already [Commitizen-friendly](#making-your-repo-commitizen-friendly), the local `commitizen` adapter will be used, instead of globally installed one.
73
+
## Commitizen for project maintainers
62
74
63
-
### Commitizen for project maintainers
64
75
As a project maintainer, making your repo Commitizen friendly allows you to select pre-existing commit message conventions or to create your own custom commit message convention. When a contributor to your repo uses Commitizen, they will be prompted for the correct fields at commit time.
65
76
66
-
####Making your repo Commitizen-friendly
77
+
## Making your repo Commitizen-friendly
67
78
68
79
For this example, we'll be setting up our repo to use [AngularJS's commit message convention](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) also known as [conventional-changelog](https://github.com/ajoslin/conventional-changelog).
Note that if you want to force install over the top of an old adapter, you can apply the `--force` argument. For more information on this, just run `commitizen help`.
89
100
90
101
The above command does three things for you.
102
+
91
103
1. Installs the cz-conventional-changelog adapter npm module
92
104
2. Saves it to package.json's dependencies or devDependencies
93
105
3. Adds the `config.commitizen` key to the root of your **package.json** as shown here:
@@ -105,21 +117,22 @@ This just tells Commitizen which adapter we actually want our contributors to us
105
117
106
118
`commitizen.path` is resolved via [require.resolve](https://nodejs.org/api/globals.html#globals_require_resolve) and supports
107
119
108
-
* npm modules
109
-
* directories relative to `process.cwd()` containing an `index.js` file
110
-
* file base names relative to `process.cwd()` with `js` extension
111
-
* full relative file names
112
-
* absolute paths.
120
+
- npm modules
121
+
- directories relative to `process.cwd()` containing an `index.js` file
122
+
- file base names relative to `process.cwd()` with `js` extension
123
+
- full relative file names
124
+
- absolute paths.
113
125
114
126
Please note that in the previous version of Commitizen we used czConfig. **czConfig has been deprecated** and you should migrate to the new format before Commitizen 3.0.0.
115
127
116
-
####Optional: Install and run Commitizen locally
128
+
## Optional: Install and run Commitizen locally
117
129
118
130
Installing and running Commitizen locally allows you to make sure that developers are running the exact same version of Commitizen on every machine.
119
131
120
132
Install Commitizen with `npm install --save-dev commitizen`.
121
133
122
134
On **NPM 5.2+** you can [use `npx`](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) to initialize the conventional changelog adapter:
@@ -139,11 +152,12 @@ And you can then add some nice npm run scripts in your package.json pointing to
139
152
140
153
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!
141
154
142
-
> **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.
155
+
> **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.
143
156
144
-
####Congratulations your repo is Commitizen-friendly. Time to flaunt it!
157
+
## Congratulations your repo is Commitizen-friendly. Time to flaunt it!
145
158
146
159
Add the Commitizen-friendly badge to your README using the following markdown:
@@ -154,31 +168,30 @@ Your badge will look like this:
154
168
155
169
It may also make sense to change your README.md or CONTRIBUTING.md to include or link to the Commitizen project so that your new contributors may learn more about installing and using Commitizen.
156
170
157
-
158
-
#### Go further
171
+
## Go further
159
172
160
173
Commitizen is great on its own, but it shines when you use it with some other amazing open source tools. Kent C. Dodds shows you how to accomplish this in his Egghead.io series, [How to write an open source javascript library](https://egghead.io/series/how-to-write-an-open-source-javascript-library). Many of the concepts can be applied to non-javascript projects as well.
161
174
162
-
####Retrying failed commits
175
+
## Retrying failed commits
163
176
164
-
As of version 2.7.1, you may attempt to retry the last commit using the `git cz --retry` command. This can be helpful when you have tests set up to run via a git precommit hook. In this scenario, you may have attempted a Commitizen commit, painstakingly filled out all of the commitizen fields, but your tests fail. In previous Commitizen versions, after fixing your tests, you would be forced to fill out all of the fields again. Enter the retry command. Commitizen will retry the last commit that you attempted in this repo without you needing to fill out the fields again.
177
+
As of version 2.7.1, you may attempt to retry the last commit using the `git cz --retry` command. This can be helpful when you have tests set up to run via a git precommit hook. In this scenario, you may have attempted a Commitizen commit, painstakingly filled out all of the commitizen fields, but your tests fail. In previous Commitizen versions, after fixing your tests, you would be forced to fill out all of the fields again. Enter the retry command. Commitizen will retry the last commit that you attempted in this repo without you needing to fill out the fields again.
165
178
166
-
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.
179
+
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.
167
180
168
181
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:
182
+
169
183
- Pass `-- --retry` as an argument for your script. i.e: `npm run commit -- --retry`
170
184
- 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`
171
185
- 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')
172
186
173
187
Note that the last two options **do not** require you to pass `--` before the args but the first **does**.
174
188
175
-
###Commitizen for multi-repo projects
189
+
## Commitizen for multi-repo projects
176
190
177
191
As a project maintainer of many projects, you may want to standardize on a single commit message
178
192
format for all of them. You can create your own node module which acts as front-end for commitizen.
179
193
180
-
#### 1. Create your own entry point script
181
-
194
+
## 1. Create your own entry point script
182
195
183
196
```
184
197
// my-cli.js
@@ -198,7 +211,7 @@ bootstrap({
198
211
});
199
212
```
200
213
201
-
####2. Add script to package.json
214
+
## 2. Add script to package.json
202
215
203
216
```
204
217
// package.json
@@ -213,14 +226,14 @@ bootstrap({
213
226
}
214
227
```
215
228
216
-
####3. Publish it to npm and use it!
229
+
## 3. Publish it to npm and use it!
217
230
218
231
```
219
232
npm install company-commit --save-dev
220
233
./node_modules/.bin/company-commit
221
234
```
222
235
223
-
###Adapters
236
+
## Adapters
224
237
225
238
We know that every project and build process has different requirements so we've tried to keep Commitizen open for extension. You can do this by choosing from any of the pre-build adapters or even by building your own. Here are some of the great adapters available to you:
226
239
@@ -236,23 +249,27 @@ We know that every project and build process has different requirements so we've
To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) but you can capture input using whatever means necessary. Just call the `commit` callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
252
+
To create an adapter, just fork one of these great adapters and modify it to suit your needs. We pass you an instance of [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) but you can capture input using whatever means necessary. Just call the `commit` callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
253
+
254
+
## Philosophy
240
255
241
-
### Philosophy
256
+
##About Commitizen
242
257
243
-
#### About Commitizen
244
258
Commitizen is an open source project that helps contributors be good open source citizens. It accomplishes this by prompting them to follow commit message conventions at commit time. It also empowers project maintainers to create or use predefined commit message conventions in their repos to better communicate their expectations to potential contributors.
245
259
246
-
#### Commitizen or Commit Hooks
260
+
## Commitizen or Commit Hooks
261
+
247
262
Both! Commitizen is not meant to be a replacement for git commit hooks. Rather, it is meant to work side-by-side with them to ensure a consistent and positive experience for your contributors. Commitizen treats the commit command as a declarative action. The contributor is declaring that they wish to contribute to your project. It is up to you as the maintainer to define what rules they should be following.
248
263
249
264
We accomplish this by letting you define which adapter you'd like to use in your project. Adapters just allow multiple projects to share the same commit message conventions. A good example of an adapter is the cz-conventional-changelog adapter.
250
265
251
-
### Related projects
252
-
*[conventional-changelog](https://github.com/conventional-changelog/conventional-changelog) – Generate a changelog from conventional commit history
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/commitizen#sponsor)]
@@ -289,4 +304,4 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
0 commit comments