git-commit-helper

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit Helper

Git 提交信息助手

Quick start

快速开始

Analyze staged changes and generate commit message:
bash
undefined
分析暂存的变更并生成提交信息:
bash
undefined

View 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并建议合适的提交信息)

undefined
undefined

Commit 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 support
Bug 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 support
Bug修复:
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
undefined

Show 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
undefined
git diff --staged path/to/file
undefined

Commit 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 object

Scope examples

范围示例

Frontend:
  • feat(ui): add loading spinner to dashboard
  • fix(form): validate email format
Backend:
  • feat(api): add user profile endpoint
  • fix(db): resolve connection pool leak
Infrastructure:
  • chore(ci): update Node version to 20
  • feat(docker): add multi-stage build
前端:
  • 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

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 structure

Template workflow

模板工作流

  1. Review changes:
    git diff --staged
  2. Identify type: Is it feat, fix, refactor, etc.?
  3. Determine scope: What part of the codebase?
  4. Write summary: Brief, imperative description
  5. Add body: Explain why and what impact
  6. Note breaking changes: If applicable
  1. 查看变更
    git diff --staged
  2. 确定类型:是feat、fix、refactor还是其他类型?
  3. 确定范围:代码库的哪个部分?
  4. 编写摘要:简洁的祈使句描述
  5. 添加正文:解释原因和影响
  6. 标记破坏性变更:如果适用的话

Interactive commit helper

交互式提交助手

Use
git add -p
for selective staging:
bash
undefined
使用
git add -p
进行选择性暂存:
bash
undefined

Stage 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"
undefined
git commit -m "type(scope): description"
undefined

Amending commits

修改提交

Fix the last commit message:
bash
undefined
修复上一次的提交信息:
bash
undefined

Amend commit message only

仅修改提交信息

git commit --amend
git commit --amend

Amend and add more changes

修改提交并添加遗漏的文件

git add forgotten-file.js git commit --amend --no-edit
undefined
git add forgotten-file.js git commit --amend --no-edit
undefined

Best practices

最佳实践

  1. Atomic commits - One logical change per commit
  2. Test before commit - Ensure code works
  3. Reference issues - Include issue numbers if applicable
  4. Keep it focused - Don't mix unrelated changes
  5. Write for humans - Future you will read this
  1. 原子提交 - 每次提交对应一个逻辑变更
  2. 提交前测试 - 确保代码可正常运行
  3. 关联问题 - 如果适用,包含问题编号
  4. 保持聚焦 - 不要混合无关变更
  5. 为人类编写 - 未来的你会阅读这些信息

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个字符
  • 摘要使用祈使语气
  • 正文解释了原因而非仅内容
  • 破坏性变更已清晰标记
  • 已包含相关问题编号