commit
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGit 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 statusReview 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.mdStep 3: Execute Commits One by One
步骤3:逐个执行提交
For each planned commit:
Stage specific files only:
bash
git add <file1> <file2>Verify staging:
bash
git statusCreate commit with conventional format:
bash
git commit -m "<type>[scope]: <description>" -m "<body>"Verify commit succeeded:
bash
git statusOnly 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 类型
| Type | Description |
|---|---|
| feat | New feature |
| fix | Bug fix |
| docs | Documentation only |
| style | Formatting, no code change |
| refactor | Code change, no new feature or fix |
| perf | Performance improvement |
| test | Adding or fixing tests |
| chore | Build process, auxiliary tools |
| 类型 | 描述 |
|---|---|
| feat | 新功能 |
| fix | Bug修复 |
| 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
规则
- Never mix unrelated changes in a single commit
- Always verify staging before committing
- Always verify success after committing
- Explain the plan before executing
- Never use or
git add .without explicit approvalgit add -A - Never include "Generated with Claude Code" or Co-Authored-By footers
- 切勿在单个提交中混合无关变更
- 提交前务必验证暂存状态
- 提交后务必验证是否成功
- 执行前先说明提交规划
- 未经明确许可,切勿使用 或
git add .git add -A - 切勿在提交中包含 "Generated with Claude Code" 或 Co-Authored-By 页脚
Example Session
示例会话
$ git status$ git statusModified: auth/login.rb, auth/signup.rb, README.md, api/client.rb
Modified: auth/login.rb, auth/signup.rb, README.md, api/client.rb
Plan:
- feat(auth): Improve login validation - auth/login.rb, auth/signup.rb
- fix(api): Handle timeout errors - api/client.rb
- 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规划:
- feat(auth): Improve login validation - auth/login.rb, auth/signup.rb
- fix(api): Handle timeout errors - api/client.rb
- 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