git-commit-helper
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit Helper Skill
Git Commit Helper Skill
Generate conventional commit messages from your git diff.
基于git diff生成符合规范的Git提交信息。
When I Activate
触发场景
- ✅ without message
git commit - ✅ User asks "what should my commit message be?"
- ✅ Staged changes exist
- ✅ User mentions commit or conventional commits
- ✅ Before creating commits
- ✅ 执行但未提供提交信息
git commit - ✅ 用户询问“我的提交信息应该怎么写?”
- ✅ 存在已暂存的变更
- ✅ 用户提及提交或规范提交
- ✅ 创建提交之前
What I Generate
生成内容
Conventional Commit Format
规范提交格式
<type>(<scope>): <subject>
<body>
<footer>Types:
- : New feature
feat - : Bug fix
fix - : Documentation changes
docs - : Code style (formatting, no logic change)
style - : Code refactoring
refactor - : Performance improvements
perf - : Test additions or fixes
test - : Build system changes
build - : CI/CD changes
ci - : Maintenance tasks
chore
<type>(<scope>): <subject>
<body>
<footer>提交类型:
- : 新功能
feat - : 修复Bug
fix - : 文档变更
docs - : 代码风格调整(仅格式化,无逻辑变更)
style - : 代码重构
refactor - : 性能优化
perf - : 添加或修复测试
test - : 构建系统变更
build - : CI/CD流程变更
ci - : 维护任务
chore
Examples
示例
Feature Addition
新增功能
bash
undefinedbash
undefinedYou staged:
你暂存了以下文件:
git add auth.service.ts login.component.tsx
git add auth.service.ts login.component.tsx
I analyze diff and suggest:
我分析diff后建议:
feat(auth): add JWT-based user authentication
- Implement login/logout functionality
- Add token management service
- Include auth guards for protected routes
- Add unit tests for auth service
Closes #42
undefinedfeat(auth): add JWT-based user authentication
- 实现登录/登出功能
- 添加令牌管理服务
- 为受保护路由添加认证守卫
- 为认证服务添加单元测试
Closes #42
undefinedBug Fix
Bug修复
bash
undefinedbash
undefinedYou staged:
你暂存了以下文件:
git add UserList.tsx
git add UserList.tsx
I suggest:
我建议:
fix(components): resolve memory leak in UserList
Fixed subscription not being cleaned up in useEffect,
causing memory leak when component unmounts.
Closes #156
undefinedfix(components): resolve memory leak in UserList
Fixed subscription not being cleaned up in useEffect,
causing memory leak when component unmounts.
Closes #156
undefinedBreaking Change
破坏性变更
bash
undefinedbash
undefinedYou staged:
你暂存了以下文件:
git add api/users.ts
git add api/users.ts
I suggest:
我建议:
feat(api): update user API response format
Changed response structure to include metadata
for better pagination and filtering support.
BREAKING CHANGE: User API now returns { data, metadata }
instead of direct array. Update client code accordingly.
undefinedfeat(api): update user API response format
Changed response structure to include metadata
for better pagination and filtering support.
BREAKING CHANGE: User API now returns { data, metadata }
instead of direct array. Update client code accordingly.
undefinedDocumentation Update
文档更新
bash
undefinedbash
undefinedYou staged:
你暂存了以下文件:
git add README.md docs/api.md
git add README.md docs/api.md
I suggest:
我建议:
docs: update API documentation with authentication examples
- Add authentication flow diagrams
- Include cURL examples for protected endpoints
- Document error responses
undefineddocs: update API documentation with authentication examples
- 添加认证流程示意图
- 包含受保护端点的cURL示例
- 文档化错误响应
undefinedAnalysis Process
分析流程
Step 1: Check Staged Changes
步骤1:检查暂存变更
bash
git diff --staged --name-only
git diff --stagedbash
git diff --staged --name-only
git diff --stagedStep 2: Categorize Changes
步骤2:分类变更
- New files → feat
- Modified files → fix, refactor, or feat
- Deleted files → chore or refactor
- Test files → test
- Documentation → docs
- 新文件 → feat
- 修改文件 → fix、refactor或feat
- 删除文件 → chore或refactor
- 测试文件 → test
- 文档 → docs
Step 3: Analyze Content
步骤3:分析内容
- What was changed?
- Why was it changed?
- What's the impact?
- Are there breaking changes?
- 变更了什么?
- 为什么进行变更?
- 变更的影响是什么?
- 是否存在破坏性变更?
Step 4: Generate Message
步骤4:生成提交信息
Subject line:
- Max 50 characters
- Imperative mood ("add" not "added")
- No period at end
- Lowercase after type
Body:
- Explain WHAT and WHY, not HOW
- Wrap at 72 characters
- Bullet points for multiple changes
Footer:
- Breaking changes:
BREAKING CHANGE: description - Issue references: ,
Closes #123Fixes #456
主题行:
- 最多50个字符
- 使用祈使语气(用“add”而非“added”)
- 结尾无句号
- 类型后使用小写
正文:
- 说明变更内容和原因,而非实现方式
- 每行不超过72个字符
- 多变更时使用项目符号
页脚:
- 破坏性变更:
BREAKING CHANGE: 描述内容 - 关联议题:、
Closes #123Fixes #456
Message Components
提交信息组件
Type Selection
类型选择
yaml
feat: New functionality
- New components, features, capabilities
fix: Bug fixes
- Resolving issues, fixing bugs
refactor: Code improvements
- No functional changes, better code structure
perf: Performance
- Speed improvements, optimization
docs: Documentation
- README, comments, guides
test: Testing
- Adding or fixing tests
style: Formatting
- Code style, linting, formatting
chore: Maintenance
- Dependencies, build config, toolingyaml
feat: 新功能
- 新组件、新特性、新能力
fix: Bug修复
- 解决问题、修复Bug
refactor: 代码优化
- 无功能变更,仅优化代码结构
perf: 性能优化
- 提升速度、优化性能
docs: 文档更新
- README、注释、指南
test: 测试相关
- 添加或修复测试
style: 格式调整
- 代码风格、代码检查、格式化
chore: 维护任务
- 依赖更新、构建配置、工具调整Scope Selection
范围选择
Common scopes:
- Component name:
feat(UserCard): ... - Module:
fix(auth): ... - Package:
chore(api): ... - Area:
docs(readme): ...
常见范围:
- 组件名称:
feat(UserCard): ... - 模块:
fix(auth): ... - 包:
chore(api): ... - 区域:
docs(readme): ...
Subject Guidelines
主题编写指南
✅ Good:
add user authenticationfix memory leak in componentupdate API documentation
❌ Bad:
- (past tense)
added user authentication - (too vague)
fixes bug - (period at end)
Update API docs.
✅ 规范示例:
add user authenticationfix memory leak in componentupdate API documentation
❌ 不规范示例:
- (过去式)
added user authentication - (过于模糊)
fixes bug - (结尾有句号)
Update API docs.
Advanced Examples
进阶示例
Multiple Changes
多文件变更
bash
undefinedbash
undefinedMultiple files in auth feature
认证功能下的多个文件变更
feat(auth): implement complete authentication system
- Add JWT token generation and validation
- Implement password hashing with bcrypt
- Create login/logout API endpoints
- Add auth middleware for protected routes
- Include refresh token functionality
Closes #42, #43, #44
undefinedfeat(auth): implement complete authentication system
- 添加JWT令牌生成与验证
- 使用bcrypt实现密码哈希
- 创建登录/登出API端点
- 为受保护路由添加认证中间件
- 包含刷新令牌功能
Closes #42, #43, #44
undefinedRefactoring
代码重构
bash
undefinedbash
undefinedCode restructuring
代码结构调整
refactor(api): extract database logic into repository pattern
Moved database queries from controllers to repository classes
for better separation of concerns and testability.
No functional changes or API modifications.
undefinedrefactor(api): extract database logic into repository pattern
Moved database queries from controllers to repository classes
for better separation of concerns and testability.
No functional changes or API modifications.
undefinedPerformance Improvement
性能优化
bash
undefinedbash
undefinedOptimization
性能优化
perf(queries): optimize user data fetching
- Implement query batching to eliminate N+1 queries
- Add database indices on frequently queried columns
- Cache user profile data with 5-minute TTL
Performance improvement: 80ms → 12ms average response time
undefinedperf(queries): optimize user data fetching
- 实现查询批处理以消除N+1查询问题
- 为频繁查询的列添加数据库索引
- 为用户配置文件数据添加5分钟TTL缓存
性能提升:平均响应时间从80ms降至12ms
undefinedGit Integration
Git集成
Pre-commit Hook
提交前钩子
I work great with pre-commit hooks:
bash
#!/bin/sh我可以与提交前钩子完美配合:
bash
#!/bin/sh.git/hooks/prepare-commit-msg
.git/hooks/prepare-commit-msg
If no commit message provided, trigger skill
如果未提供提交信息,触发本工具
if [ -z "$2" ]; then
Skill suggests message based on staged changes
echo "# Suggested commit message (edit as needed)" > "$1"
fi
undefinedif [ -z "$2" ]; then
工具基于暂存变更生成建议的提交信息
echo "# 建议的提交信息(可按需编辑)" > "$1"
fi
undefinedAmending Commits
修正提交信息
bash
undefinedbash
undefinedPoor initial message
初始提交信息质量不佳
git commit -m "fix stuff"
git commit -m "fix stuff"
Amend with better message
修正为更优的提交信息
I suggest improved message based on changes
我会基于变更内容生成更完善的建议信息
git commit --amend
undefinedgit commit --amend
undefinedSandboxing Compatibility
沙箱兼容性
Works without sandboxing: ✅ Yes
Works with sandboxing: ✅ Yes
May need network access for:
- Fetching issue details from GitHub API
- Checking if issue numbers are valid
Sandbox config (optional):
json
{
"network": {
"allowedDomains": [
"api.github.com"
]
}
}无需沙箱即可运行: ✅ 是
支持沙箱环境: ✅ 是
可能需要网络访问的场景:
- 从GitHub API获取议题详情
- 验证议题编号是否有效
沙箱配置(可选):
json
{
"network": {
"allowedDomains": [
"api.github.com"
]
}
}Customization
自定义配置
Custom Commit Types
自定义提交类型
Edit SKILL.md to add company-specific types:
yaml
deploy: Deployment
migrate: Database migrations
hotfix: Production hotfixes编辑SKILL.md添加公司专属的提交类型:
yaml
deploy: 部署操作
migrate: 数据库迁移
hotfix: 生产环境热修复Custom Scopes
自定义范围
Train the skill to recognize your project structure:
yaml
Common scopes: auth, api, ui, database, admin, mobile训练工具识别你的项目结构:
yaml
Common scopes: auth, api, ui, database, admin, mobileMessage Templates
提交信息模板
Customize message format for your team:
bash
undefined为你的团队自定义提交信息格式:
bash
undefinedStandard format
标准格式
feat(scope): subject
feat(scope): subject
Your custom format
自定义格式
[JIRA-123] feat(scope): subject
undefined[JIRA-123] feat(scope): subject
undefinedTips for Best Messages
提交信息编写技巧
- Be specific: "fix login button" not "fix bug"
- Use imperative mood: "add" not "added" or "adds"
- Include context: Why this change was needed
- Reference issues: Always include issue numbers
- Breaking changes: Always flag in footer
- 具体明确:使用“修复登录按钮”而非“修复Bug”
- 使用祈使语气:用“add”而非“added”或“adds”
- 包含上下文:说明变更的原因
- 关联议题:始终包含议题编号
- 破坏性变更:在页脚中明确标记
Common Patterns
常见场景示例
Frontend Changes
前端变更
feat(ui): add responsive navigation menu
fix(components): resolve prop validation warning
style(css): update button hover effectsfeat(ui): 新增响应式导航菜单
fix(components): 修复属性验证警告
style(css): 更新按钮 hover 效果Backend Changes
后端变更
feat(api): add user pagination endpoint
fix(database): resolve connection pool exhaustion
perf(queries): add database indices for user lookupsfeat(api): 新增用户分页端点
fix(database): 解决连接池耗尽问题
perf(queries): 为用户查询添加数据库索引Infrastructure Changes
基础设施变更
ci: add automated deployment pipeline
build: update dependencies to latest versions
chore(docker): optimize container image sizeci: 新增自动化部署流水线
build: 将依赖更新至最新版本
chore(docker): 优化容器镜像大小Related Tools
相关工具
- code-reviewer skill: Reviews code before commit
- @docs-writer sub-agent: Generates changelog from commits
- /review command: Pre-commit code review
- code-reviewer skill: 提交前代码审查
- @docs-writer sub-agent: 基于提交记录生成变更日志
- /review 命令: 提交前代码审查
Integration
集成流程
With code-reviewer
与code-reviewer集成
bash
undefinedbash
undefined1. Write code
1. 编写代码
2. code-reviewer flags issues
2. code-reviewer标记问题
3. Fix issues
3. 修复问题
4. Stage changes
4. 暂存变更
5. I generate commit message
5. 我生成提交信息
git commit # Uses my suggested message
undefinedgit commit # 使用我建议的提交信息
undefinedWith /review Command
与/review命令集成
bash
undefinedbash
undefined1. Make changes
1. 进行代码变更
/review --scope staged # Review before commit
/review --scope staged # 提交前审查
2. Address findings
2. 处理审查意见
3. Stage final changes
3. 暂存最终变更
4. I generate commit message
4. 我生成提交信息
git commit
undefinedgit commit
undefinedLearn More
更多参考
- Conventional Commits
- Git Best Practices
- Customization Guide
- Conventional Commits
- Git最佳实践
- 自定义指南