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.
Commitizen is currently tested against Node.js 12, 14, & 16, although it may work in older versions of Node.js. You should also have npm 6 or greater.
Installation is as simple as running the following command (if you see EACCES
error, reading fixing npm permissions may help):
npm install -g commitizen
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
.
Alternatively, if you are using npm 5.2+ you can use npx
instead of installing globally:
npx cz
or as an npm script:
... "scripts": { "commit": "cz" }
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 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
, but npx cz
will use the streamich/git-cz adapter. To fix this, you need to first make your repo Commitizen friendly
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:
# 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
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
.
The above command does three things for you:
package.json
's dependencies
or devDependencies
config.commitizen
key to the root of your package.json
file as shown here:... "config": { "commitizen": { "path": "cz-conventional-changelog" } }
Alternatively, Commitizen configs may be added to a .czrc
file:
{ "path": "cz-conventional-changelog" }
This just tells Commitizen which adapter we actually want our contributors to use when they try to commit to this repo.
commitizen.path
is resolved via require.resolve and supports:
process.cwd()
containing an index.js
fileprocess.cwd()
with .js
extensionPlease 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.
Installing and running Commitizen locally allows you to make sure that developers are running the exact same version of Commitizen on every machine.
Install Commitizen with npm install --save-dev commitizen
.
On npm 5.2+ you can use npx
to initialize the conventional changelog adapter:
npx commitizen init cz-conventional-changelog --save-dev --save-exact
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.
You can then initialize the conventional changelog adapter using: ./node_modules/.bin/commitizen init cz-conventional-changelog --save-dev --save-exact
And you can then add some nice npm scripts in your package.json
file pointing to the local version of Commitizen:
... "scripts": { "commit": "cz" }
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!
NOTE: If you are using
precommit
hooks thanks to something likehusky
, 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 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 workaround is to prevent the npm-triggered precommit script.
git commit
This example shows how to incorporate Commitizen into the existing git commit
workflow by using git hooks and the --hook
command-line option. This is useful for project maintainers
who wish to ensure the proper commit format is enforced on contributions from those unfamiliar with Commitizen.
Once either of these methods is implemented, users running git commit
will be presented with an interactive Commitizen session that helps them write useful commit messages.
NOTE: This example assumes that the project has been set up to use Commitizen locally.
Update .git/hooks/prepare-commit-msg
with the following code:
#!/bin/bash exec < /dev/tty && node_modules/.bin/cz --hook || true
For husky
users, add the following configuration to the project's package.json
file:
"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.
Add the "Commitizen friendly" badge to your README using the following markdown:
[](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
files to include or link to the Commitizen project so that your new contributors may learn more about installing and using Commitizen.
Install commitizen
globally, if you have not already.
npm install -g commitizen
Install your preferred commitizen
adapter globally (for example cz-conventional-changelog
).
npm install -g cz-conventional-changelog
Create a .czrc
file in your home
directory, with path
referring to the preferred, globally-installed, commitizen
adapter
echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc
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.
Pro tip: You can use all the git commit
options
with git cz
. For example: git cz -a
.
If your repository is a Node.js project, making it Commitizen friendly is super easy.
If your repository is already Commitizen friendly, the local commitizen
adapter will be used, instead of globally installed one.
As a project maintainer of many projects, you may want to standardize on a single commit message format for all of them. You can create your own node module which acts as a front-end for Commitizen.
// 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" } });
package.json
file// package.json { "name": "company-commit", "bin": "./my-cli.js", "dependencies": { "commitizen": "^2.7.6", "cz-conventional-changelog": "^1.1.5" } }
npm install --save-dev company-commit ./node_modules/.bin/company-commit
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-built 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 necessary. Just call the commit
callback with a string and we'll be happy. Publish it to npm, and you'll be all set!
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.
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.
It is important to note that if you are running cz
from an npm script (let's say it is called commit
) you will need to do one of the following:
-- --retry
as an argument for your script. i.e: npm run commit -- --retry
cz
executable directly. i.e: npx cz --retry
Note that the last two options do not require you to pass --
before the args but the first does.
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.
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. Many of the concepts can be applied to non-JavaScript projects as well.
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,
字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等 。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号