用途
commit-helper 是一个用于创建符合 Conventional Commits 规范的 Git 提交信息的技能(Skill)。它帮助开发者在提交代码时生成结构化、格式统一的提交信息。
触发方式
当出现以下情况时,该技能会被激活:
- 要求提交更改
- 提到提交信息
- 请求 git commit 格式化
- 说出 "commit" 或 "git commit"
提交信息格式
<type>(<scope>): <subject>
<body>
类型(Types)
| 类型 | 说明 |
|---|---|
| feat | 新功能 |
| fix | 缺陷修复 |
| docs | 仅文档变更 |
| style | 不影响代码含义的变更(格式化等) |
| refactor | 既不修复缺陷也不新增功能的代码变更 |
| perf | 提升性能的代码变更 |
| test | 添加缺失的测试或修正现有测试 |
| chore | 构建过程或辅助工具的变更 |
| ci | CI 配置文件和脚本的变更 |
| build | 影响构建系统或外部依赖的变更 |
作用域(Scope)
作用域用于表明受影响的代码库区域:
- 前端:components、hooks、store、styles、utils
- 后端:api、models、services、database、auth
- DevOps:ci、deploy、docker
项目特定的作用域同样可以接受。
编写指南
主题行
- 使用祈使语气("add feature",而非 "added feature" 或 "adds feature")
- 结尾不加句号
- 最多 50 个字符
- 具体且简洁
正文(Body)
- 与主题行之间空一行
- 用正文说明做了什么和为什么,而不是怎么做
- 每行 72 个字符换行
- 提及任何破坏性变更
页脚(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 # Too vague, no type/scope
fixed bug # No context about which bug
feat: added feature # Redundant ("feat" means new feature)
Feat(User): Add Login # Incorrect capitalization
feat: A really really really long subject line that exceeds the recommended limit # Too long
破坏性变更
引入破坏性变更时,在页脚添加 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.
工作流程
撰写提交信息时:
- 查看变更 —— 运行 git diff 了解改了什么
- 确定类型 —— 判断变更的类型
- 确定作用域 —— 判断受影响的区域
- 编写主题行 —— 创建清晰简洁的主题行
- 编写正文 —— 说明做了什么和为什么(如需要)
- 添加页脚 —— 引用 issue 或标注破坏性变更
验证
使用验证脚本检查提交信息格式:
python3 scripts/validate_commit.py "feat(scope): add behavior"
参考文档
- 完整规范见 references/conventional-commits.md
- 更多示例见 references/examples.md
- 推荐的作用域命名见 references/scopes.md
限制
资料未提供该技能的具体平台兼容性、安装方式、依赖要求以及收费信息。