commit

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Git Commit Assistant

Git 提交助手

Analyze git changes and create logical, well-structured commits using conventional commit format.
分析Git变更,并使用Conventional Commit格式创建逻辑清晰、结构合理的提交。

When to Use

适用场景

  • User asks to commit changes
  • Multiple unrelated changes need separate commits
  • Changes need conventional commit formatting
  • 用户要求提交变更
  • 多个不相关的变更需要拆分到不同提交中
  • 变更需要遵循Conventional Commit格式

Workflow

工作流程

Step 1: Review Current State

步骤1:查看当前状态

Run git status to see all changes:
bash
git status
Review both staged and unstaged changes. Identify modified, added, and deleted files.
运行git status查看所有变更:
bash
git status
查看暂存和未暂存的所有变更,识别已修改、新增和删除的文件。

Step 2: Analyze and Plan Commits

步骤2:分析并规划提交

Group changes into logical commits based on:
  • Feature boundaries: Files that implement the same feature together
  • Type of change: Separate fixes from features from refactors
  • Scope: Group by component, module, or area of the codebase
Present the commit plan to the user before proceeding:
I see the following logical commits:
1. feat(auth): Add password reset - auth/reset.rb, auth/mailer.rb
2. fix(api): Handle null responses - api/client.rb
3. docs: Update README - README.md
根据以下规则将变更分组为逻辑提交:
  • 功能边界:实现同一功能的文件放在一起
  • 变更类型:将修复、新功能、重构分开
  • 范围:按组件、模块或代码库区域分组
在执行前先向用户展示提交规划:
我梳理出以下逻辑提交:
1. feat(auth): Add password reset - auth/reset.rb, auth/mailer.rb
2. fix(api): Handle null responses - api/client.rb
3. docs: Update README - README.md

Step 3: Execute Commits One by One

步骤3:逐个执行提交

For each planned commit:
Stage specific files only:
bash
git add <file1> <file2>
Verify staging:
bash
git status
Create commit with conventional format:
bash
git commit -m "<type>[scope]: <description>" -m "<body>"
Verify commit succeeded:
bash
git status
Only proceed to the next commit after verifying the current one completed.
针对每个规划好的提交:
仅暂存指定文件:
bash
git add <file1> <file2>
验证暂存状态:
bash
git status
使用规范格式创建提交:
bash
git commit -m "<type>[scope]: <description>" -m "<body>"
验证提交成功:
bash
git status
必须确认当前提交完成后,再进行下一个提交。

Conventional Commit Types

Conventional Commit 类型

TypeDescription
featNew feature
fixBug fix
docsDocumentation only
styleFormatting, no code change
refactorCode change, no new feature or fix
perfPerformance improvement
testAdding or fixing tests
choreBuild process, auxiliary tools
类型描述
feat新功能
fixBug修复
docs仅文档变更
style格式调整,无代码逻辑变更
refactor代码重构,无新功能或Bug修复
perf性能优化
test添加或修复测试
chore构建流程、辅助工具相关变更

Commit Message Format

提交消息格式

<type>[optional scope]: <description>

[optional body]

[optional footer]
  • Description: Imperative mood, lowercase, no period ("add feature" not "Added feature.")
  • Body: Explain what and why, not how
  • Scope: Component or area affected (auth, api, db, ui)
<type>[可选范围]: <描述>

[可选正文]

[可选页脚]
  • 描述:使用祈使语气、小写、无句号(例如用"add feature"而非"Added feature.")
  • 正文:说明变更内容和原因,而非实现方式
  • 范围:受影响的组件或区域(如auth、api、db、ui)

Rules

规则

  1. Never mix unrelated changes in a single commit
  2. Always verify staging before committing
  3. Always verify success after committing
  4. Explain the plan before executing
  5. Never use
    git add .
    or
    git add -A
    without explicit approval
  6. Never include "Generated with Claude Code" or Co-Authored-By footers
  1. 切勿在单个提交中混合无关变更
  2. 提交前务必验证暂存状态
  3. 提交后务必验证是否成功
  4. 执行前先说明提交规划
  5. 未经明确许可,切勿使用
    git add .
    git add -A
  6. 切勿在提交中包含 "Generated with Claude Code" 或 Co-Authored-By 页脚

Example Session

示例会话

$ git status
$ git status

Modified: auth/login.rb, auth/signup.rb, README.md, api/client.rb

Modified: auth/login.rb, auth/signup.rb, README.md, api/client.rb

Plan:
  1. feat(auth): Improve login validation - auth/login.rb, auth/signup.rb
  2. fix(api): Handle timeout errors - api/client.rb
  3. docs: Add authentication guide - README.md
Executing commit 1... $ git add auth/login.rb auth/signup.rb $ git status # verify only auth files staged $ git commit -m "feat(auth): improve login validation" -m "Add email format check and rate limiting" $ git status # verify commit succeeded
Executing commit 2... [continues...]
undefined
规划:
  1. feat(auth): Improve login validation - auth/login.rb, auth/signup.rb
  2. fix(api): Handle timeout errors - api/client.rb
  3. docs: Add authentication guide - README.md
正在执行提交1... $ git add auth/login.rb auth/signup.rb $ git status # 验证仅暂存了auth相关文件 $ git commit -m "feat(auth): improve login validation" -m "Add email format check and rate limiting" $ git status # 验证提交成功
正在执行提交2... [继续执行...]
undefined