mcpField
C
conventional-commit

conventional-commit

github.com/trancong12102开发757 次安装6 周前更新
代码仓库

关于 conventional-commit

用于根据 Git 变更生成 Conventional Commits 消息的技能,指导开发者检查差异、暂存文件、选择类型与范围并提交,同时限定不做无关代码修改。

主要功能

  1. 01分析 Git 状态与差异
  2. 02选择提交类型和范围
  3. 03生成规范格式的提交消息
  4. 04暂存指定文件或全部文件
  5. 05使用 HEREDOC 格式提交
  6. 06避免未获请求的推送或修改

适用场景

  1. 01审查代码变更后创建提交
  2. 02将变更归类为功能、修复或维护
  3. 03添加破坏性变更说明和问题引用

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/trancong12102/agentskills --skill conventional-commit

安装后在 Claude Code 中输入/conventional-commit确认已加载。

详细介绍

Conventional Commit 生成器

生成符合 Conventional Commits 1.0.0 规范的提交消息。

工作流

  1. 运行 git status 和 git diff HEAD,分析变更

  2. 暂存文件:仅暂存用户指定的文件,或使用 git add -A 暂存所有文件

  3. 根据变更确定类型和范围

  4. 结合用户提示生成提交消息

  5. 使用 HEREDOC 格式提交,以保留格式:

    git commit -m "$(cat <<'EOF'
    <type>(<scope>): <description>
    
    <body>
    
    <footer>
    EOF
    )"
    
  6. 输出:<hash> <subject>

范围边界

可以做: 分析 Git 变更、生成消息、暂存文件、提交

不要做: 修改代码、推送(除非用户要求)、创建分支、未经请求修改提交

提交格式

<type>[optional scope][!]: <description>

[optional body]

[optional footer(s)]

类型选择

变更类型SemVer
新功能featMINOR
Bug 修复fixPATCH
性能改进perfPATCH
代码重构(不改变行为)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 允许使用空格。

破坏性变更

有两种方式可以标明破坏性变更(可同时使用以加强强调):

  1. 感叹号: 在主题行的冒号前添加感叹号

    feat(api)!: remove deprecated endpoints
    
  2. 页脚: 在页脚中添加 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 codefix(auth): validate token expiration具体明确
Fixed bugfix: prevent null pointer in parser使用现在时
WIP不要提交 WIP提交完整单元
Add feature.feat: add dark mode toggle末尾不加句号
Added teststest: add unit tests for parser使用祈使语气
FEAT: Add...feat: add...类型使用小写
misc changeschore: update dependencies描述清晰

评论

支持 Markdown