Git commit 规范

Angular’s Format

以angular团队的提交格式作为标准,Each commit message consists of a header, a body, and a footer.

1
2
3
4
5
<type>[optional scope]: <description>
blank line
[optional body]
blank line
[optional footer]

header格式如下:

1
2
3
<type>(<scope>): <short summary>

<type> -> Commit Type: build|ci|docs|feat|fix|perf|refactor|test

type

type 的分类如下表示:

  • build: 编译相关的内容,发布版本、对项目构建或者依赖的改动,即npm、gulp、yarn等文件的修改
  • ci: 修改了持续集成,示例范围:Travis、Circle、BrowserStack、SauceLabs
  • docs:修改md或其余说明性文档。
  • feat:新功能(feature)。
  • fix/to:修复bug
  • perf:优化相关,比如提升性能、体验。
  • refactor:重构(即不是新增功能,也不是修改bug的代码变动)。
  • style:格式(不影响代码逻辑和运行的变动)。
  • test:增加测试。
  • chore:杂务,构建过程或辅助工具的变动等。
  • revert:回滚到上一个版本。在正文中添加”This reverts commit hash”,其中hash值表示被回滚前的提交
  • sync:同步主线或分支的Bug。

    scope

    optional

作为type字段的补充型说明

description

简单明了的描述清楚事件

body

optional

对本次 commit 的详细描述,可以分成多行。
(1)使用第一人称现在时,比如使用change而不是changed或changes。
(2)应该说明代码变动的动机,以及与以前行为的对比。

Breaking changes
不兼容修改指的是本次提交修改了不兼容之前版本的API或者环境变量
所有不兼容修改都必须在页脚中作为中断更改块提到,以BREAKING CHANGE:开头,后跟一个空格或者两个换行符,其余的信息就是对此次修改的描述,修改的理由和修改注释

examples(from Conventional Commits )

包含了描述并且脚注中有破坏性变更的提交说明

1
2
3
feat: allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files

包含了 ! 字符以提醒注意破坏性变更的提交说明

1
feat!: send an email to the customer when a product is shipped

包含了范围和破坏性变更 ! 的提交说明

1
feat(api)!: send an email to the customer when a product is shipped

包含了 ! 和 BREAKING CHANGE 脚注的提交说明

1
2
3
chore!: drop support for Node 6

BREAKING CHANGE: use JavaScript features not available in Node 6.

不包含正文的提交说明

1
docs: correct spelling of CHANGELOG

包含范围的提交说明

1
feat(lang): add polish language

包含多行正文和多行脚注的提交说明

1
2
3
4
5
6
7
8
9
10
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

参考链接

Author

LLLLAAAA

Posted on

2025-04-17

Updated on

2025-04-20

Licensed under

Comments