SuperAPI AI 工具集

Git Commit Helper

编程与开发

查看项目

更新于 10-15 13:11

技能介绍

用途

Git Commit Helper 用于在提交代码时生成描述性的提交信息。它通过分析 git diff(暂存变更)来理解改动内容,并在用户请求帮助撰写提交信息或审查暂存变更时提供支持。

主要能力

  • 分析暂存的代码变更,并据此建议提交信息。

  • 遵循 Conventional Commits 格式撰写提交信息:

    <type>(<scope>): <description>
    
    [optional body]
    
    [optional footer]
    
  • 支持以下提交类型:

    • feat:新功能
    • fix:缺陷修复
    • docs:文档变更
    • style:代码风格变更(格式化、缺少分号等)
    • refactor:代码重构
    • test:新增或更新测试
    • chore:维护任务

使用方式

资料给出的快速开始流程:先查看暂存变更,再生成提交信息。

# 查看暂存变更
git diff --staged

# 基于变更生成提交信息
# (Claude 会分析 diff 并建议一条提交信息)

分析变更时可用命令:

# 显示变更文件
git status

# 显示详细变更
git diff --staged

# 显示统计信息
git diff --staged --stat

# 显示指定文件的变更
git diff --staged path/to/file

交互式提交可使用选择性暂存:

# 交互式暂存变更
git add -p

# 审查已暂存内容
git diff --staged

# 使用提交信息提交
git commit -m "type(scope): description"

修订提交:

# 仅修订提交信息
git commit --amend

# 修订并加入更多变更
git add forgotten-file.js
git commit --amend --no-edit

模板工作流:审查变更(git diff --staged)→ 确定类型(feat、fix、refactor 等)→ 确定作用域(代码库的哪一部分)→ 撰写摘要(简短、祈使语气)→ 添加正文(说明原因与影响)→ 标注破坏性变更(如适用)。

提交信息指南

应当(DO):

  • 使用祈使语气("add feature" 而不是 "added feature")
  • 首行控制在 50 个字符以内
  • 首字母大写
  • 摘要末尾不加句号
  • 在正文中解释 WHY 而不只是 WHAT

不应(DON'T):

  • 使用模糊信息,如 "update" 或 "fix stuff"
  • 在摘要中包含技术实现细节
  • 在摘要行写段落
  • 使用过去时

示例

功能提交:

feat(auth): add JWT authentication

Implement JWT-based authentication system with:
- Login endpoint with token generation
- Token validation middleware
- Refresh token support

缺陷修复:

fix(api): handle null values in user profile

Prevent crashes when user profile fields are null.
Add null checks before accessing nested properties.

重构:

refactor(database): simplify query builder

Extract common query patterns into reusable functions.
Reduce code duplication in database layer.

多文件提交:

refactor(core): restructure authentication module

- Move auth logic from controllers to service layer
- Extract validation into separate validators
- Update tests to use new structure
- Add integration tests for auth flow

Breaking change: Auth service now requires config object

作用域示例:

  • 前端:feat(ui): add loading spinner to dashboard;fix(form): validate email format
  • 后端:feat(api): add user profile endpoint;fix(db): resolve connection pool leak
  • 基础设施:chore(ci): update Node version to 20;feat(docker): add multi-stage build

破坏性变更:

feat(api)!: restructure API response format

BREAKING CHANGE: All API responses now follow JSON:API spec

Previous format:
{ "data": {...}, "status": "ok" }

New format:
{ "data": {...}, "meta": {...} }

Migration guide: Update client code to handle new response structure

最佳实践

  • 原子提交:每次提交只做一个逻辑变更
  • 提交前测试:确保代码可运行
  • 引用议题:如适用,包含议题编号
  • 保持聚焦:不要混入无关变更
  • 为人类书写:未来的你会读到它

提交信息检查清单

  • 类型适当(feat/fix/docs 等)
  • 作用域具体明确
  • 摘要不超过 50 个字符
  • 摘要使用祈使语气
  • 正文解释 WHY 而不只是 WHAT
  • 破坏性变更清晰标注
  • 包含相关议题编号

适用场景与限制

适用场景:需要撰写 Git 提交信息、审查暂存变更、按 Conventional Commits 规范整理提交内容时。上述内容均来自资料本身;除此之外的功能、收费、价格、平台、效果等暂未提供。