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 can still be helpful). No more digging through CONTRIBUTING.md to find what the preferred format is. Get instant feedback on your commit message formatting and be prompted for required fields.
Installation is as simple as running the following command (add sudo if on OSX/Linux):
npm install -g commitizen
Now, simply use git cz
instead of git commit
when committing.
When you're working in a Commitizen friendly repository, you'll be prompted to fill in any required fields and your commit messages will be formatted according to the the standards defined by project maintainers.
If you're not working in a Commitizen friendly repository, then git cz
will work just the same as git commit
.
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.
For this example, we'll be setting up our repo to use AngularJS's commit message convention also known as conventional-changelog.
First, install the Commitizen cli tools:
npm install commitizen -g
Next, initialize your project to use the cz-conventional-changelog adapter by typing:
commitizen init cz-conventional-changelog --save --save-exact
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
.
Then just add the czConfig
field to the root of your package.json with the following contents:
...
"czConfig": {
"path": "node_modules/cz-conventional-changelog"
}
This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.
Add the Commitizen-friendly badge to your README using the following markdown:
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
Your badge will look like this:
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.
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:
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 but you can capture input using whatever means neccesary. Just call the commit
callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
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.
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.
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-changlog adapter.
@JimTheDev (Jim Cummins, author) @kentcdodds @accraze @kytwb @Den-dp
Special thanks to @stevelacy, whose gulp-git project makes commitizen possible.