这里有一篇 大佬的文章 可以参考
我这里是借助了工具(熟悉之后可以不借助工具),使用的是 commitizen/cz-cli + commitizen/cz-conventional-changelog
Commit Message 规范
目前规范使用较多的是 Angular 团队的规范 ,它的 message 格式如下:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
对应的中文含义是
标题行: 必填, 描述主要修改类型和内容
主题内容: 描述为什么修改, 做了什么样的修改, 以及开发的思路等等
页脚注释: 放 Breaking Changes 或 Closed Issues
分别由如下部分构成:
type: commit 的类型
feat: 新特性
fix: 修改问题
refactor: 代码重构
docs: 文档修改
style: 代码格式修改, 注意不是 css 修改
test: 测试用例修改
chore: 其他修改, 比如构建流程, 依赖管理.
scope: commit 影响的范围, 比如: route, component, utils, build...
subject: commit 的概述
body: commit 具体修改内容, 可以分为多行,
footer: 一些备注, 通常是 BREAKING CHANGE 或修复的 bug 的链接.
安装工具
npm install -g commitizen cz-conventional-changelog
之后的提交把 git commit 换成 git cz
后续
- 如何在 commit 的时候关闭issue?
第一方式:commit message 里,这里推荐第一种方式
Write a short, imperative tense description of the change (max 95 chars):
输入关键字: close, closes, closing, closed, fixed, fix, resolved + #id 都可以关闭。比如 fix #1
第二种方式:在 footer 里
Does this change affect any open issues? Yes
If issues are closed, the commit requires a body. Please enter a longer description of the commit itself:
xxx
Add issue references (e.g. "fix #123", "re #123".):