smart-commit
Splits uncommitted changes into multiple logical commits by functionality. Use when asked to organize commits, split changes, or create atomic commits.
When & Why to Use This Skill
Smart Commit is an essential Git utility that automates the organization of uncommitted changes into logical, atomic commits. By analyzing code diffs and categorizing updates into standard types—such as features, bug fixes, and refactors—it ensures a clean, readable repository history and strictly adheres to Conventional Commit standards, significantly improving project maintainability.
Use Cases
- Cleaning up a large workspace: Automatically group multiple unrelated changes into separate, meaningful commits after a long coding session.
- Enforcing Conventional Commits: Standardize commit messages across a project using the 'type: description' format to facilitate automated changelog generation.
- Enhancing Code Reviews: Break down complex PRs into smaller, functional commits, making it easier for reviewers to follow the logic and intent of each change.
- Atomic Staging: Intelligently split changes within a single file into different commits based on their specific functionality (e.g., separating a bug fix from a style change).
| name | smart-commit |
|---|---|
| description | Splits uncommitted changes into multiple logical commits by functionality. Use when asked to organize commits, split changes, or create atomic commits. |
Smart Commit
将未提交的更改按功能/逻辑分成多个独立的 commit。
工作流程
分析更改
- 运行
git status查看所有未提交的文件 - 运行
git diff和git diff --cached查看具体更改内容
- 运行
分类更改
- 阅读每个文件的更改内容
- 按功能/逻辑将更改分组:
- 新功能
- Bug 修复
- 重构
- 文档更新
- 配置变更
- 测试相关
- 样式/格式化
逐组提交
- 对每组相关更改:
git add <相关文件...> git commit -m "<type>: <简洁描述>" - 如果单个文件包含多个功能的更改,使用
git add -p分块暂存
- 对每组相关更改:
Commit 消息格式
使用 Conventional Commits 格式:
feat: 添加用户登录功能fix: 修复分页计算错误refactor: 重构数据库连接逻辑docs: 更新 API 文档test: 添加用户模块单元测试chore: 更新依赖版本style: 格式化代码
注意事项
- 每个 commit 应该是独立的、可编译的
- 相关的更改放在同一个 commit
- 不相关的更改分开提交
- commit 消息要清晰描述更改内容
- 提交前确认分组是否合理