Commit Tidy
Analyze staged/unstaged changes and recommend whether to split into multiple commits.
When to use
- - Before committing large changesets
- User asks "should I split this commit?"
- Reviewing changes that touch many files
- Ensuring atomic, reviewable commits
Split Decision Criteria
Split when
- 1. Unrelated functionality changes
- Feature A + Bug fix B → 2 commits
- UI change + API change (if independent) → 2 commits
- 2. Wide file spread
- Changes span 5+ directories with no common purpose
- Frontend + Backend + Config all modified
- 3. Mixed change types
- Refactoring + New feature → 2 commits
- Formatting + Logic change → 2 commits
- Dependency update + Code change → 2 commits
- 4. Large diff size
- 500+ lines changed across unrelated areas
- Multiple components modified independently
- 5. Different reviewers needed
- Changes require different domain expertise
- Security-sensitive + general changes
Keep together when
- 1. Single logical change
- Feature requires touching multiple files
- Refactoring that must be atomic
- 2. Dependent changes
- API change + caller updates
- Schema change + migration + model update
- 3. Related cleanup
- Feature + directly related tests
- Bug fix + regression test
Squash Criteria
When analyzing multiple commits, recommend squashing as well as splitting.
Squash when
- 1. Same type + same purpose
-
test: A test +
test: B test (tests for the same feature) → squash into 1
-
fix: typo A +
fix: typo B (same review feedback) → squash into 1
- 2. Commits split per loop by automated agents
- Autonomous agents like Ralph commit per loop → squash if same purpose
- Example: proxy test in loop 1, OIDC test in loop 2 → INLINECODE4
- 3. Consecutive WIP commits
-
wip: in progress +
feat: complete → squash into one feat
Don't squash
- 1. Commits with different types — keep
test + chore + feat separate - Commits belonging to different PRs/issues
- Independent changes that may need to be reverted
Output format (when recommending squash)
CODEBLOCK0
Instructions
Step 1: Analyze changes
CODEBLOCK1
Step 2: Categorize files
Group changed files by:
- - Feature/Component: Which feature does this belong to?
- Change type: feat, fix, refactor, style, test, docs, chore
- Directory: Are changes localized or spread out?
Step 3: Identify boundaries
Look for natural split points:
- - Different conventional commit types
- Independent functionality
- Separate test files from implementation (if tests are for different features)
Step 4: Recommend split strategy
Provide specific recommendations:
CODEBLOCK2
Step 5: Execute split (if requested)
CODEBLOCK3
Quick Reference
File spread heuristic
| Files | Directories | Recommendation |
|---|
| 1-5 | 1-2 | Usually single commit |
| 5-10 |
2-3 | Review for split |
| 10+ | 4+ | Likely needs split |
Change type combinations to split
| Combination | Split? |
|---|
| feat + feat (unrelated) | ✅ Yes |
| feat + related test |
❌ No |
| fix + unrelated refactor | ✅ Yes |
| refactor + style (same files) | ❌ No |
| chore(deps) + feat | ✅ Yes |
Output Format
Analysis results should include:
- 1. List of changed files with categories
- Whether split is needed and why
- Specific commit splitting plan
- Suggested commit messages for each
- Execution commands (if requested)
Commit Tidy
分析已暂存/未暂存的变更,并建议是否拆分为多个提交。
使用场景
- - 提交大型变更集之前
- 用户询问我应该拆分这个提交吗?
- 审查涉及多个文件的变更
- 确保原子性、可审查的提交
拆分决策标准
需要拆分的情况
- 1. 不相关的功能变更
- 功能A + Bug修复B → 2个提交
- UI变更 + API变更(若相互独立)→ 2个提交
- 2. 文件分布广泛
- 变更涉及5个以上目录且无共同目的
- 前端 + 后端 + 配置均被修改
- 3. 混合变更类型
- 重构 + 新功能 → 2个提交
- 格式化 + 逻辑变更 → 2个提交
- 依赖更新 + 代码变更 → 2个提交
- 4. 差异规模过大
- 不相关区域变更超过500行
- 多个组件独立修改
- 5. 需要不同审查者
- 变更涉及不同领域专业知识
- 安全敏感 + 常规变更
应保持在一起的情况
- 1. 单一逻辑变更
- 功能需要修改多个文件
- 必须保持原子性的重构
- 2. 依赖变更
- API变更 + 调用方更新
- 模式变更 + 迁移 + 模型更新
- 3. 相关清理
- 功能 + 直接相关的测试
- Bug修复 + 回归测试
合并标准
分析多个提交时,同时建议合并和拆分。
需要合并的情况
- 1. 相同类型 + 相同目的
- test: A测试 + test: B测试(同一功能的测试)→ 合并为1个
- fix: 拼写错误A + fix: 拼写错误B(同一审查反馈)→ 合并为1个
- 2. 自动化代理按循环拆分的提交
- 像Ralph这样的自主代理按循环提交 → 若目的相同则合并
- 示例:循环1中的代理测试,循环2中的OIDC测试 → test: 添加单元测试
- 3. 连续的WIP提交
- wip: 进行中 + feat: 完成 → 合并为一个功能提交
不应合并的情况
- 1. 不同类型的提交 — 保持test + chore + feat分离
- 属于不同PR/问题的提交
- 可能需要回滚的独立变更
输出格式(建议合并时)
建议:合并2个提交为1个
之前(2个提交):
- - 441b966a test(dt): OIDC认证、代理、SSO测试
- e2b6503a test(dt): OIDC路由测试(登录、回调、我的信息)
之后(1个提交):
理由:相同类型(test),相同功能(OIDC认证),代理循环拆分
操作说明
第一步:分析变更
bash
检查暂存变更
git diff --cached --stat
git diff --cached --name-only
检查未暂存变更
git diff --stat
git status
第二步:分类文件
按以下维度对变更文件分组:
- - 功能/组件:属于哪个功能?
- 变更类型:feat、fix、refactor、style、test、docs、chore
- 目录:变更是局部化还是分散的?
第三步:识别边界
寻找自然拆分点:
- - 不同的常规提交类型
- 独立的功能
- 将测试文件与实现文件分离(如果测试针对不同功能)
第四步:建议拆分策略
提供具体建议:
分析结果
变更文件(N个文件)
- - src/api/...(3个文件)- API端点
- src/components/...(2个文件)- UI组件
- tests/...(2个文件)- 测试
建议:拆分为N个提交
提交1:feat: 添加用户资料API
- - src/api/user.ts
- src/api/types.ts
- tests/api/user.test.ts
提交2:feat: 添加资料UI组件
- - src/components/Profile.tsx
- src/components/Profile.css
- tests/components/Profile.test.tsx
理由
- - API和UI可以独立运行
- 每个可由不同审查者审查
第五步:执行拆分(如被要求)
bash
取消所有暂存
git reset HEAD
暂存第一个提交的文件
git add src/api/ tests/api/
git commit -m feat: 添加用户资料API
暂存第二个提交的文件
git add src/components/ tests/components/
git commit -m feat: 添加资料UI组件
快速参考
文件分布启发式
2-3 | 审查是否需要拆分 |
| 10+ | 4+ | 可能需要拆分 |
需要拆分的变更类型组合
| 组合 | 拆分? |
|---|
| feat + feat(不相关) | ✅ 是 |
| feat + 相关测试 |
❌ 否 |
| fix + 不相关重构 | ✅ 是 |
| refactor + style(相同文件) | ❌ 否 |
| chore(deps) + feat | ✅ 是 |
输出格式
分析结果应包括:
- 1. 带分类的变更文件列表
- 是否需要拆分及原因
- 具体的提交拆分计划
- 每个提交的建议提交信息
- 执行命令(如被要求)