git-commit-helper
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit Commit Helper
Git 提交信息助手
Quick start
快速开始
Analyze staged changes and generate commit message:
bash
undefined分析暂存的变更并生成提交信息:
bash
undefinedView staged changes
查看暂存的变更
git diff --staged
git diff --staged
Generate commit message based on changes
根据变更生成提交信息
(Claude will analyze the diff and suggest a message)
(Claude 会分析diff并建议合适的提交信息)
undefinedundefinedCommit message format
提交信息格式
Follow conventional commits format:
<type>(<scope>): <description>
[optional body]
[optional footer]遵循规范提交(conventional commits)格式:
<type>(<scope>): <description>
[可选正文]
[可选页脚]Types
类型
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Code style changes (formatting, missing semicolons)
- refactor: Code refactoring
- test: Adding or updating tests
- chore: Maintenance tasks
- feat: 新功能
- fix: 修复Bug
- docs: 文档变更
- style: 代码样式变更(格式化、补充分号等)
- refactor: 代码重构
- test: 添加或更新测试
- chore: 维护任务
Examples
示例
Feature commit:
feat(auth): add JWT authentication
Implement JWT-based authentication system with:
- Login endpoint with token generation
- Token validation middleware
- Refresh token supportBug fix:
fix(api): handle null values in user profile
Prevent crashes when user profile fields are null.
Add null checks before accessing nested properties.Refactor:
refactor(database): simplify query builder
Extract common query patterns into reusable functions.
Reduce code duplication in database layer.功能提交:
feat(auth): add JWT authentication
Implement JWT-based authentication system with:
- Login endpoint with token generation
- Token validation middleware
- Refresh token supportBug修复:
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.Analyzing changes
分析变更
Review what's being committed:
bash
undefined查看即将提交的内容:
bash
undefinedShow files changed
显示已变更的文件
git status
git status
Show detailed changes
显示详细变更内容
git diff --staged
git diff --staged
Show statistics
显示变更统计
git diff --staged --stat
git diff --staged --stat
Show changes for specific file
显示特定文件的变更
git diff --staged path/to/file
undefinedgit diff --staged path/to/file
undefinedCommit message guidelines
提交信息指南
DO:
- Use imperative mood ("add feature" not "added feature")
- Keep first line under 50 characters
- Capitalize first letter
- No period at end of summary
- Explain WHY not just WHAT in body
DON'T:
- Use vague messages like "update" or "fix stuff"
- Include technical implementation details in summary
- Write paragraphs in summary line
- Use past tense
建议做法:
- 使用祈使语气(比如“添加功能”而非“已添加功能”)
- 第一行不超过50个字符
- 首字母大写
- 摘要末尾不要加句号
- 在正文中解释原因而非仅说明内容
避免做法:
- 使用模糊的表述比如“更新”或“修复问题”
- 在摘要中包含技术实现细节
- 在摘要行写段落
- 使用过去式
Multi-file commits
多文件提交
When committing multiple related changes:
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当提交多个相关变更时:
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 objectScope examples
范围示例
Frontend:
feat(ui): add loading spinner to dashboardfix(form): validate email format
Backend:
feat(api): add user profile endpointfix(db): resolve connection pool leak
Infrastructure:
chore(ci): update Node version to 20feat(docker): add multi-stage build
前端:
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
Breaking changes
破坏性变更
Indicate breaking changes clearly:
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(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 structureTemplate workflow
模板工作流
- Review changes:
git diff --staged - Identify type: Is it feat, fix, refactor, etc.?
- Determine scope: What part of the codebase?
- Write summary: Brief, imperative description
- Add body: Explain why and what impact
- Note breaking changes: If applicable
- 查看变更:
git diff --staged - 确定类型:是feat、fix、refactor还是其他类型?
- 确定范围:代码库的哪个部分?
- 编写摘要:简洁的祈使句描述
- 添加正文:解释原因和影响
- 标记破坏性变更:如果适用的话
Interactive commit helper
交互式提交助手
Use for selective staging:
git add -pbash
undefined使用进行选择性暂存:
git add -pbash
undefinedStage changes interactively
交互式暂存变更
git add -p
git add -p
Review what's staged
查看已暂存的内容
git diff --staged
git diff --staged
Commit with message
附带提交信息完成提交
git commit -m "type(scope): description"
undefinedgit commit -m "type(scope): description"
undefinedAmending commits
修改提交
Fix the last commit message:
bash
undefined修复上一次的提交信息:
bash
undefinedAmend commit message only
仅修改提交信息
git commit --amend
git commit --amend
Amend and add more changes
修改提交并添加遗漏的文件
git add forgotten-file.js
git commit --amend --no-edit
undefinedgit add forgotten-file.js
git commit --amend --no-edit
undefinedBest practices
最佳实践
- Atomic commits - One logical change per commit
- Test before commit - Ensure code works
- Reference issues - Include issue numbers if applicable
- Keep it focused - Don't mix unrelated changes
- Write for humans - Future you will read this
- 原子提交 - 每次提交对应一个逻辑变更
- 提交前测试 - 确保代码可正常运行
- 关联问题 - 如果适用,包含问题编号
- 保持聚焦 - 不要混合无关变更
- 为人类编写 - 未来的你会阅读这些信息
Commit message checklist
提交信息检查清单
- Type is appropriate (feat/fix/docs/etc.)
- Scope is specific and clear
- Summary is under 50 characters
- Summary uses imperative mood
- Body explains WHY not just WHAT
- Breaking changes are clearly marked
- Related issue numbers are included
- 类型选择恰当(feat/fix/docs等)
- 范围具体清晰
- 摘要不超过50个字符
- 摘要使用祈使语气
- 正文解释了原因而非仅内容
- 破坏性变更已清晰标记
- 已包含相关问题编号