关于 conventional-commit
用于根据 Git 变更生成 Conventional Commits 消息的技能,指导开发者检查差异、暂存文件、选择类型与范围并提交,同时限定不做无关代码修改。
主要功能
- 01分析 Git 状态与差异
- 02选择提交类型和范围
- 03生成规范格式的提交消息
- 04暂存指定文件或全部文件
- 05使用 HEREDOC 格式提交
- 06避免未获请求的推送或修改
适用场景
- 01审查代码变更后创建提交
- 02将变更归类为功能、修复或维护
- 03添加破坏性变更说明和问题引用
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ trancong12102/ agentskills --skill conventional-commit安装后在 Claude Code 中输入/conventional-commit确认已加载。
详细介绍
Conventional Commit 生成器
生成符合 Conventional Commits 1.0.0 规范的提交消息。
工作流
-
运行
git status和git diff HEAD,分析变更 -
暂存文件:仅暂存用户指定的文件,或使用
git add -A暂存所有文件 -
根据变更确定类型和范围
-
结合用户提示生成提交消息
-
使用 HEREDOC 格式提交,以保留格式:
git commit -m "$(cat <<'EOF' <type>(<scope>): <description> <body> <footer> EOF )" -
输出:
<hash> <subject>
范围边界
可以做: 分析 Git 变更、生成消息、暂存文件、提交
不要做: 修改代码、推送(除非用户要求)、创建分支、未经请求修改提交
提交格式
<type>[optional scope][!]: <description>
[optional body]
[optional footer(s)]
类型选择
| 变更 | 类型 | SemVer |
|---|---|---|
| 新功能 | feat | MINOR |
| Bug 修复 | fix | PATCH |
| 性能改进 | perf | PATCH |
| 代码重构(不改变行为) | refactor | - |
| 代码风格/格式调整(不改变逻辑) | style | - |
| 添加/更新测试 | test | - |
| 仅更新文档 | docs | - |
| 构建系统/依赖项 | build | - |
| CI/CD 配置 | ci | - |
| 撤销先前的提交 | revert | - |
| 其他维护任务 | chore | - |
注意: 只有
feat和fix会影响 SemVer。破坏性变更(任何带感叹号的类型,或包含BREAKING CHANGE页脚)会触发 MAJOR 版本更新。
主题行
- 最大长度: 72 个字符(建议不超过 50 个字符,以便阅读)
- 格式:
type(scope): description或type: description - 语气: 使用祈使语气的现在时(用 "add",而不是 "added" 或 "adds")
- 大小写: 首字母小写
- 标点: 末尾不加句号
范围
范围用于说明代码库中受影响的部分。使用描述模块、组件或区域的名词。
常见范围模式:
- 组件/模块:
feat(auth):、fix(parser):、refactor(api): - 文件/区域:
docs(readme):、test(unit):、build(webpack): - 功能:
feat(dark-mode):、fix(checkout):
正文
- 与主题行之间空一行
- 说明是什么和为什么,而不是如何做
- 可以包含多个段落(段落之间空一行)
- 每行最多 72 个字符
页脚
页脚遵循 git trailer 格式,使用 :<space> 或 <space># 分隔符。
常见页脚:
BREAKING CHANGE: <description>- API 发生破坏性变更Refs: #123或Refs: JIRA-456- 引用问题Closes: #123或Fixes: #123- 关闭问题Co-authored-by: Name <email>- 致谢共同作者Reviewed-by: Name <email>- 致谢审阅者Acked-by: Name- 致谢认可者
注意: 页脚标记使用
-替代空格(例如,使用Reviewed-by,而不是Reviewed by)。例外情况:BREAKING CHANGE允许使用空格。
破坏性变更
有两种方式可以标明破坏性变更(可同时使用以加强强调):
-
感叹号: 在主题行的冒号前添加感叹号
feat(api)!: remove deprecated endpoints -
页脚: 在页脚中添加
BREAKING CHANGE:或BREAKING-CHANGE:feat(api): redesign authentication flow BREAKING CHANGE: OAuth tokens now expire after 1 hour instead of 24 hours.
示例
简单功能:
feat: add email notifications for new messages
带范围的 Bug 修复:
fix(cart): prevent ordering with empty shopping cart
文档更新:
docs(api): add authentication examples to README
带正文和页脚的破坏性变更:
feat(api)!: redesign user authentication endpoints
Migrate from session-based auth to JWT tokens for better scalability.
The new system supports refresh tokens and configurable expiration.
BREAKING CHANGE: /api/login now returns JWT instead of session cookie.
Clients must include Authorization header with Bearer token.
Refs: JIRA-1337
撤销提交:
revert: let us never again speak of the noodle incident
Refs: 676104e, a215868
多范围变更(使用最重要的范围):
feat(auth): add OAuth2 support with Google provider
Adds Google OAuth2 login flow with automatic account linking.
Co-authored-by: Jane Doe <[email protected]>
Closes: #42
反面模式
避免这些常见错误:
| 错误示例 | 正确示例 | 原因 |
|---|---|---|
Update code | fix(auth): validate token expiration | 具体明确 |
Fixed bug | fix: prevent null pointer in parser | 使用现在时 |
WIP | 不要提交 WIP | 提交完整单元 |
Add feature. | feat: add dark mode toggle | 末尾不加句号 |
Added tests | test: add unit tests for parser | 使用祈使语气 |
FEAT: Add... | feat: add... | 类型使用小写 |
misc changes | chore: update dependencies | 描述清晰 |