git-convention

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Convention Skill

Git提交规范技能

Generate conventional git commit messages following Angular commit convention format.
生成遵循Angular提交规范格式的标准化Git提交信息。

Commit Message Format

提交信息格式

<type>(<scope>): <subject>

<body>

<footer>
<type>(<scope>): <subject>

<body>

<footer>

Type

类型

Must be one of:
TypeDescription
feat
A new feature
fix
A bug fix
docs
Documentation only changes
style
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
refactor
A code change that neither fixes a bug nor adds a feature
perf
A code change that improves performance
test
Adding missing tests or correcting existing tests
build
Changes that affect the build system or external dependencies
ci
Changes to CI configuration files and scripts
chore
Other changes that don't modify src or test files
revert
Reverts a previous commit
必须为以下类型之一:
类型描述
feat
新增功能
fix
修复Bug
docs
仅修改文档
style
不影响代码逻辑的变更(空白字符、格式调整、缺少分号等)
refactor
既不修复Bug也不新增功能的代码变更
perf
提升性能的代码变更
test
添加缺失测试或修正现有测试
build
影响构建系统或外部依赖的变更
ci
修改CI配置文件或脚本
chore
其他不修改源码或测试文件的变更
revert
回滚之前的提交

Scope

范围

The scope should be the name of the npm package affected (as indicated by package.json).
Example scopes:
  • core
  • auth
  • user
  • api
  • ui
范围应为受影响的npm包名称(参考package.json)。
示例范围:
  • core
  • auth
  • user
  • api
  • ui

Subject

主题

The subject contains a succinct description of the change:
  • Use imperative, present tense: "change" not "changed" nor "changes"
  • Don't capitalize the first letter
  • No period (.) at the end
主题需简洁描述变更内容:
  • 使用现在时、祈使语气:用"change"而非"changed"或"changes"
  • 首字母无需大写
  • 结尾不加句号(.)

Body

正文

The body should include the motivation for the change and contrast this with previous behavior:
  • Use imperative, present tense: "change" not "changed" nor "changes"
  • Include the motivation for the change and contrast this with previous behavior
正文应包含变更的动机,并与之前的行为进行对比:
  • 使用现在时、祈使语气:用"change"而非"changed"或"changes"
  • 说明变更动机,并对比之前的行为

Footer

页脚

The footer should contain any information about Breaking Changes and is also the place to reference GitHub issues that this commit Closes.
Breaking Changes should start with the word
BREAKING CHANGE:
with a space or two newlines.
页脚需包含任何关于突破性变更的信息,同时也是引用此提交关闭的GitHub问题的位置。
突破性变更需以
BREAKING CHANGE:
开头,后跟空格或两个换行符。

Examples

示例

Feature with scope

带范围的功能新增

feat(auth): add login with Google

Implement OAuth2 authentication flow using Google Sign-In
- Add GoogleSignInButton component
- Update auth service to handle OAuth tokens
- Add error handling for failed authentication

Closes #123
feat(auth): add login with Google

Implement OAuth2 authentication flow using Google Sign-In
- Add GoogleSignInButton component
- Update auth service to handle OAuth tokens
- Add error handling for failed authentication

Closes #123

Bug fix

Bug修复

fix(api): handle null response from user endpoint

Previously, null responses would crash the app.
Now returns empty user object instead.
fix(api): handle null response from user endpoint

Previously, null responses would crash the app.
Now returns empty user object instead.

Breaking change

突破性变更

feat(core): change user model structure

BREAKING CHANGE: User.id is now String instead of int.

All database queries and API calls need to be updated
to handle string IDs.
feat(core): change user model structure

BREAKING CHANGE: User.id is now String instead of int.

All database queries and API calls need to be updated
to handle string IDs.

Documentation

文档修改

docs(readme): update installation instructions

Added step for installing required system dependencies.
docs(readme): update installation instructions

Added step for installing required system dependencies.

Refactoring

代码重构

refactor(user): extract validation logic to separate class

Move all user validation logic from UserService to
new UserValidator class for better testability.
refactor(user): extract validation logic to separate class

Move all user validation logic from UserService to
new UserValidator class for better testability.

Multiple paragraphs in body

正文包含多段落

feat(api): add pagination support

Implement cursor-based pagination for list endpoints.

- Add PaginationFilter class
- Update repository methods to accept pagination params
- Add tests for pagination edge cases

This improves performance for large datasets and
reduces memory usage.
feat(api): add pagination support

Implement cursor-based pagination for list endpoints.

- Add PaginationFilter class
- Update repository methods to accept pagination params
- Add tests for pagination edge cases

This improves performance for large datasets and
reduces memory usage.

Revert

回滚提交

revert: feat(auth): add login with Facebook

This reverts commit 1a2b3c4d
revert: feat(auth): add login with Facebook

This reverts commit 1a2b3c4d

Best Practices

最佳实践

DO:
  • Use the present tense ("add" not "added")
  • Use the imperative mood ("move" not "moves")
  • Limit the first line to 72 characters or less
  • Reference issues in the footer
  • Explain what and why, not how
  • Keep subject line short and descriptive
  • Use body to explain what and why vs. how
DON'T:
  • Use past tense
  • Use period at the end of subject
  • Capitalize first letter of subject
  • Mix multiple types in one commit
  • Write vague subjects like "update stuff"
  • Include how you fixed it in the message
  • Exceed 72 characters on first line
建议
  • 使用现在时(用"add"而非"added")
  • 使用祈使语气(用"move"而非"moves")
  • 首行限制在72字符以内
  • 在页脚引用相关问题
  • 说明变更内容和原因,而非实现方式
  • 主题行简洁明了
  • 用正文说明变更内容和原因,而非实现方式
避免
  • 使用过去式
  • 主题行结尾加句号
  • 主题行首字母大写
  • 单个提交混合多种类型
  • 编写模糊的主题,如"update stuff"
  • 在信息中包含修复的实现细节
  • 首行超过72字符

Changelog Generation

变更日志生成

Conventional commits enable automatic changelog generation:
bash
undefined
标准化提交支持自动生成变更日志:
bash
undefined

Using conventional-changelog

Using conventional-changelog

npm install -g conventional-changelog conventional-changelog -p angular -i CHANGELOG.md -s
undefined
npm install -g conventional-changelog conventional-changelog -p angular -i CHANGELOG.md -s
undefined

Commit Linting

提交信息校验

Enforce commit message conventions with commitlint:
json
// commitlint.config.js
{
  "extends": ["@commitlint/config-angular"],
  "rules": {
    "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"]],
    "type-case": [2, "always", "lower-case"],
    "subject-empty": [2, "never"],
    "subject-case": [0]
  }
}
使用commitlint强制遵循提交信息规范:
json
// commitlint.config.js
{
  "extends": ["@commitlint/config-angular"],
  "rules": {
    "type-enum": [2, "always", ["feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert"]],
    "type-case": [2, "always", "lower-case"],
    "subject-empty": [2, "never"],
    "subject-case": [0]
  }
}

Quick Reference

快速参考

feat: add new feature
fix: fix bug
docs: update documentation
style: format code (no logic change)
refactor: refactor code
perf: improve performance
test: add/update tests
build: change build system
ci: change CI config
chore: other changes
revert: revert previous commit
feat: add new feature
fix: fix bug
docs: update documentation
style: format code (no logic change)
refactor: refactor code
perf: improve performance
test: add/update tests
build: change build system
ci: change CI config
chore: other changes
revert: revert previous commit