commit-helper

commit-helper

帮助遵循 Conventional Commits 规范编写 Git 提交信息。当用户要求提交更改、编写提交信息、格式化提交或提及 git 提交时使用此技能。

80Star
14Fork
更新于 2026/9/15
SKILL.md
只读
名称
commit-helper
描述

帮助遵循 Conventional Commits 规范编写 Git 提交信息。当用户要求提交更改、编写提交信息、格式化提交或提及 git 提交时使用此技能。

Commit Message Helper

用于遵循 Conventional Commits 规范创建格式正确的 Git 提交信息的技能。

何时触发此技能

当您执行以下操作时,此技能会自动激活:

  • 请求提交更改
  • 提及提交信息(commit messages)
  • 要求格式化 git 提交
  • 输入“commit”或“git commit”

提交信息格式

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

<body>

<footer>

类型(Types)

类型 描述
feat 新功能
fix 修复 bug
docs 仅文档变更
style 不影响代码含义的变更(格式化等)
refactor 既不修复 bug 也不添加功能的代码重构
perf 提高性能的代码变更
test 添加缺失的测试或更正现有测试
chore 对构建过程或辅助工具的变更
ci 对 CI 配置文件和脚本的变更
build 影响构建系统或外部依赖项的变更

作用域(Scope)

作用域应指示受影响的代码库区域:

  • 前端:components、hooks、store、styles、utils
  • 后端:api、models、services、database、auth
  • DevOps:ci、deploy、docker
  • 也接受特定于项目的自定义作用域

编写指南

主题行(Subject Line)

  • 使用祈使句式(用“add feature”,不用“added feature”或“adds feature”)
  • 末尾不加句号
  • 最多 50 个字符
  • 保持具体且简明

正文(Body)

  • 用空行将主题与正文分隔开
  • 在正文中说明改动了什么以及为什么改动,而不是怎么做的
  • 每行在 72 个字符处换行
  • 说明任何破坏性变更(breaking changes)

页脚(Footer)

  • 关联 Issue:Closes #123、Fixes #456、Refs #789
  • 多个 Issue:Closes #123, #456, #789
  • 破坏性变更:以 BREAKING CHANGE: 开头,后跟具体说明

示例

优秀示例

feat(auth): add OAuth2 login support

Implement OAuth2 authentication flow to allow users to log in
with their Google or GitHub accounts.

This change adds:
- New OAuth2 middleware for handling callbacks
- Updated login UI with social login buttons
- User profile synchronization

Closes #123
fix(api): resolve race condition in user creation

The concurrent user creation requests could result in duplicate
email entries. Added unique constraint and proper error handling.

Fixes #456
refactor(user): simplify profile update logic

Extracted common validation logic into a reusable function
to reduce code duplication across profile update endpoints.
docs: update API documentation with new endpoints

Added documentation for the v2 user management endpoints
including request/response examples and error codes.

不良示例

updated stuff                    # 太模糊,缺少类型/作用域
fixed bug                        # 缺少关于修复了哪个 bug 的上下文
feat: added feature              # 冗余(“feat”本身已代表新功能)
Feat(User): Add Login            # 大小写不正确
feat: A really really really long subject line that exceeds the recommended limit  # 太长

破坏性变更(Breaking Changes)

当引入破坏性变更时,请在页脚添加 BREAKING CHANGE::

feat(api): migrate to REST v2

The API endpoints have been restructured for better consistency.
Old endpoints are deprecated and will be removed in v3.0.

BREAKING CHANGE: `/api/v1/users` is now `/api/v2/users`.
All consumers must update their integration by 2025-03-01.

工作流程

编写提交信息时的步骤:

  1. 审查变更 - 运行 git diff 了解修改了哪些内容
  2. 确定类型 - 确定变更的类型
  3. 确定作用域 - 确定受影响的区域
  4. 编写主题 - 撰写清晰、简明的主题行
  5. 编写正文 - 说明内容和原因(如需要)
  6. 添加页脚 - 关联 Issue 或标注破坏性变更

校验

使用校验脚本检查提交信息格式:

python3 scripts/validate_commit.py "feat(scope): add behavior"

参考文档

  • 查看 references/conventional-commits.md 获取完整规范
  • 查看 references/examples.md 获取更多示例
  • 查看 references/scopes.md 获取推荐的作用域命名规则