Git 规范
约 1367 字大约 5 分钟
GitConventional Commitscooperate
已发布
2025-09-17
当然,随着人工智能技术的发展,Commit Message 已经可以自动生成了,但我们还是得知道基本的格式和背后的道理。
Git 提交规范
业内普遍采用 Conventional Commits「约定式提交」规范,中文站点。
很简单,它长这样:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
<type>
: 此次提交的「类型」,BREAKING CHANGE「破坏性更新」 应该在其后加一个!
,包括:- feat: 表示在代码库中修复了一个 bug
- fix: 表示在代码库中新增了一个功能
- build: 用于修改项目构建系统,例如修改依赖库、外部接口或者升级 Node 版本等;
- chore: 用于对非业务性代码进行修改,例如修改构建流程或者工具配置等;
- ci: 用于修改持续集成流程,例如修改 Travis、Jenkins 等工作流配置;
- docs: 用于修改文档,例如修改 README 文件、API 文档等;
- style: 用于修改代码的样式,例如调整缩进、空格、空行等;
- refactor: 用于重构代码,例如修改代码结构、变量名、函数名等但不修改功能逻辑;
- perf: 用于优化性能,例如提升代码的性能、减少内存占用等;
- test: 用于修改测试用例,例如添加、删除、修改代码的测试用例等。
[optional scope]
: 可选,本次更改代码涉及的范围,如视图层 view<description>
: 描述更改[optional body]
: 正文,可选,进一步阐述更改的细节,如修复 #666
[optional footer(s)]
: 脚注,可选,可以写上协作者的细节Signed-off-by: someone<someone@github.com>
;BREAKING CHANGE: ...
示例
包含了描述并且脚注中有破坏性变更的提交说明
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
包含了 ! 字符以提醒注意破坏性变更的提交说明
feat!: send an email to the customer when a product is shipped
包含了范围和破坏性变更 ! 的提交说明
feat(api)!: send an email to the customer when a product is shipped
包含了 ! 和 BREAKING CHANGE 脚注的提交说明
chore!: drop support for Node 6
BREAKING CHANGE: use JavaScript features not available in Node 6.
不包含正文的提交说明
docs: correct spelling of CHANGELOG
包含范围的提交说明
feat(lang): add polish language
包含多行正文和多行脚注的提交说明
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
Reviewed-by: Z
Refs: #123
注意事项
勾选项容易搞混或遗忘,警钟长鸣。