关于 Git Commit Helper
Git Commit Helper 是用于检查 Git 暂存变更并起草 Conventional Commits 格式提交信息的技能。它引导开发者确定类型、范围、摘要、正文及破坏性变更说明。
主要功能
- 01分析暂存区差异
- 02建议 Conventional Commits 格式
- 03选择提交类型和范围
- 04遵循精简摘要规范
- 05标注破坏性变更
适用场景
- 01为功能提交起草信息
- 02编写清晰的缺陷修复摘要
- 03在提交中说明破坏性变更
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ davila7/ claude-code-templates --skill git-commit-helper安装后在 Claude Code 中输入/git-commit-helper确认已加载。
详细介绍
Git Commit Helper
快速开始
分析已暂存的更改并生成提交信息:
# View staged changes
git diff --staged
# Generate commit message based on changes
# (Claude will analyze the diff and suggest a message)
提交信息格式
遵循 conventional commits 格式:
<type>(<scope>): <description>
[optional body]
[optional footer]
类型
- feat:新功能
- fix:缺陷修复
- docs:文档更改
- style:代码风格更改(格式化、缺失的分号)
- refactor:代码重构
- test:添加或更新测试
- chore:维护任务
示例
功能提交:
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.
分析更改
查看将要提交的内容:
# Show files changed
git status
# Show detailed changes
git diff --staged
# Show statistics
git diff --staged --stat
# Show changes for specific file
git diff --staged path/to/file
提交信息指南
应当:
- 使用祈使语气(“add feature” 而非 “added feature”)
- 首行保持在 50 个字符以内
- 首字母大写
- 摘要末尾不加句号
- 在正文中解释 WHY 而不仅是 WHAT
不应:
- 使用 “update” 或 “fix stuff” 之类的含糊信息
- 在摘要中包含技术实现细节
- 在摘要行中写成段落
- 使用过去时
多文件提交
提交多个相关更改时:
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 dashboardfix(form): validate email format
后端:
feat(api): add user profile endpointfix(db): resolve connection pool leak
基础设施:
chore(ci): update Node version to 20feat(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
模板工作流
- 查看更改:
git diff --staged - 确定类型:是 feat、fix、refactor 还是其他?
- 确定范围:涉及代码库的哪一部分?
- 撰写摘要:简短、使用祈使语气的描述
- 添加正文:解释原因和影响
- 注明破坏性更改:如适用
交互式提交助手
使用 git add -p 进行选择性暂存:
# Stage changes interactively
git add -p
# Review what's staged
git diff --staged
# Commit with message
git commit -m "type(scope): description"
修补提交
修正上一次提交信息:
# Amend commit message only
git commit --amend
# Amend and add more changes
git add forgotten-file.js
git commit --amend --no-edit
最佳实践
- 原子提交 - 每次提交只包含一个逻辑更改
- 提交前测试 - 确保代码可正常运行
- 引用 issue - 如适用,包含 issue 编号
- 保持聚焦 - 不要混合不相关的更改
- 为人类而写 - 未来的你会读到它
提交信息检查清单
- 类型恰当(feat/fix/docs/等)
- 范围具体且清晰
- 摘要少于 50 个字符
- 摘要使用祈使语气
- 正文解释 WHY 而不仅是 WHAT
- 破坏性更改已清晰标明
- 已包含相关 issue 编号
评论
支持 Markdown