智能化的 Git 提交命令,自动分析代码变更并生成符合规范的提交信息。
Generates conventional commit messages by analyzing staged changes and managing the entire commit workflow.
/plugin marketplace add Protagonistss/claude-plugins/plugin install git-tools@claude-plugins-protagonisths智能化的 Git 提交命令,自动分析代码变更并生成符合规范的提交信息。
/commit 命令帮助开发者进行标准化的 Git 提交,自动分析代码变更、生成符合 Conventional Commits 规范的提交信息,并提供完整的提交流程管理。
/commit [options]
--type - 提交类型(feat, fix, refactor, docs, style, test, chore, perf, ci, build)--scope - 提交影响范围--interactive - 交互式模式(默认)--auto - 自动模式,不询问直接提交--split - 智能拆分提交建议--check - 仅检查,不实际提交--template - 使用自定义模板--amend - 修改上一个提交--push - 提交后自动推送到远程仓库--push-to <remote/branch> - 推送到指定的远程分支--no-push - 明确不推送(默认行为)--create-branch - 如果需要,自动创建新分支--branch-type <type> - 指定分支类型(feature, hotfix, release)--branch-name <name> - 自定义分支名称--check-lint - 提交前运行代码检查--check-test - 提交前运行测试--check-format - 检查代码格式--check-all - 运行所有检查(默认配置)--create-pr - 推送后创建 Pull Request--draft-pr - 创建草稿 PR--assign <user> - 指定 PR 审查人--label <label> - 添加 PR 标签--no-verify - 跳过 Git hooks(谨慎使用)# 智能分析和提交
/commit
# 自动模式,不需要交互
/commit --auto
# 仅检查变更,不提交
/commit --check
# 指定功能类型和范围
/commit --type feat --scope auth
# 修复类型
/commit --type fix --scope api
# 重构类型
/commit --type refactor --scope performance
# 提交并推送到当前分支的远程跟踪分支
/commit --push
# 提交并推送到指定分支
/commit --push-to origin/main
# 强制推送(谨慎使用)
/commit --push --force-with-lease
# 自动创建 feature 分支并提交
/commit --create-branch --branch-type feature
# 创建指定名称的分支
/commit --create-branch --branch-name feature/user-auth
# 创建 hotfix 分支
/commit --branch-type hotfix --push
# 提交前运行所有检查
/commit --check-all
# 只运行 lint 检查
/commit --check-lint
# 运行测试和 lint
/commit --check-test --check-lint
# 提交并推送后创建 PR
/commit --push --create-pr
# 创建草稿 PR 并指定审查人
/commit --push --draft-pr --assign @reviewer
# 带标签的 PR
/commit --push --create-pr --label enhancement
🔍 分析代码变更...
📋 Git 状态:
- 已暂存: 5 个文件
- 未暂存: 2 个文件
- 未跟踪: 1 个文件
📂 变更详情:
+ src/components/LoginForm.jsx (新增)
M src/api/auth.js (修改)
M tests/auth.test.js (修改)
A .env.example (新增)
D src/utils/old-helper.js (删除)
自动分析变更内容,识别提交类型:
根据文件路径自动识别影响范围:
const scopeMappings = {
'src/auth/': 'auth',
'src/api/': 'api',
'src/ui/': 'ui',
'src/components/': 'components',
'docs/': 'docs',
'tests/': 'test',
'config/': 'config',
'scripts/': 'scripts'
};
基于分析结果生成标准化提交信息:
feat(auth): 实现用户登录功能
- 添加登录表单组件
- 集成认证 API
- 实现错误处理
- 添加单元测试
Closes #123
提供友好的交互界面:
💡 建议提交信息:
feat(auth): 实现用户登录功能
📝 详细描述:
- 添加登录表单组件
- 集成认证 API
- 实现错误处理
- 添加单元测试
✅ 是否继续提交? [Y/n/edit/skip] y
feat(scope): 添加功能描述
## 主要变更
- 具体变更内容1
- 具体变更内容2
## 影响
- 对现有功能的影响
- 新增的能力
## 测试
- 测试覆盖率情况
Closes #issue-number
fix(scope): 修复问题描述
## 问题原因
- 问题产生的原因
- 影响范围
## 修复方案
- 修复的具体方法
- 预防措施
Fixes #issue-number
refactor(scope): 重构描述
## 重构原因
- 代码异味问题
- 性能瓶颈
## 改进效果
- 可读性提升
- 性能提升数据
- 维护性改善
项目根目录创建 .commit-config.json:
{
"commit": {
"defaultType": "feat",
"defaultScope": "app",
"maxSubjectLength": 50,
"requireBody": true,
"requireIssue": false,
"autoDetectScope": true,
"pushDefault": false,
"addSignature": false, // 禁止添加任何 AI 工具签名,保持提交历史专业性和纯粹性
"preCommitChecks": ["lint", "test"],
"prePushChecks": ["security", "build"],
"branchProtection": {
"main": ["require-review", "require-ci"],
"develop": ["require-ci"]
},
"autoCreateBranch": true,
"branchNaming": {
"feature": "feat/{scope}-{description}",
"hotfix": "fix/{version}-{description}",
"release": "release/{version}"
},
"customTypes": [
{
"type": "perf",
"description": "性能优化"
}
],
"scopes": [
"auth",
"api",
"ui",
"db",
"config",
"docs"
]
}
}
对于大型变更,智能建议拆分方案:
/commit --split
📊 变更分析:
- 总变更: 23 个文件
- 建议: 拆分为 3 个提交
💡 拆分建议:
1. feat(auth): 用户认证基础设施
- 包含: auth.js, auth.test.js, config/auth.js
2. feat(ui): 登录界面组件
- 包含: LoginForm.jsx, Login.css, Login.test.jsx
3. fix(api): 修复认证 API 问题
- 包含: user.js, middleware/auth.js
是否按照建议拆分? [Y/n]
# 批量提交所有暂存的变更
/commit --batch
# 批量提交并推送多个分支
/commit --batch --push --branches "feature/*"
分析提交历史,提供改进建议:
/commit --analyze-history
📊 提交历史分析:
- 最近7天: 15 个提交
- 类型分布: feat(40%), fix(20%), refactor(15%)
- 平均提交大小: 3.2 个文件
💡 改进建议:
- 考虑合并小型提交
- 增加 chore 类型提交
- 保持提交信息一致性
❌ 没有检测到暂存的变更
💡 使用 'git add <files>' 暂存文件
📋 或使用 'git add -A' 暂存所有变更
⚠️ 检测到未暂存的变更:
- src/example.js (未暂存)
💡 是否要暂存这些文件? [Y/n/all]
❌ 推送失败: 远程有新的提交
💡 建议先拉取最新变更:
git pull --rebase origin main
# 取消最近的提交(保留变更)
/commit --undo
# 完全删除最近的提交
/commit --undo --hard
# 恢复到指定的提交
/commit --restore <commit-hash>
# 提交前自动运行代码审查
/commit --check --review
# 输出:
🔍 运行代码审查...
📋 审查结果:
- 1 个安全问题 (高优先级)
- 2 个性能建议
- 3 个代码规范问题
❌ 发现问题,建议修复后再提交
# 提交并触发 CI
/commit --push --trigger-ci
# 输出:
✅ 提交成功
📤 推送到远程
🔄 触发 CI 流程...
🔗 构建链接: https://ci.example.com/build/123
当使用 --check 参数时,git-tools 会自动检测 code-review 插件是否安装:
/commit --check
如果 code-review 插件未安装,会提示:
⚠️ code-review 插件未安装
💡 安装后可以获得更全面的代码质量检查
📦 安装命令: claude plugin install code-review
当使用 --check-test 参数时,会自动检测 test-generator 插件:
/commit --check-test
如果 test-generator 插件未安装,会提示:
⚠️ test-generator 插件未安装
💡 安装后可以自动生成缺失的测试用例
📦 安装命令: claude plugin install test-generator
原子性提交
清晰的提交信息
及时提交
使用分支
A: 建议使用 feature 分支,定期提交,最后通过 PR 合并:
/commit --branch-type feature --create-branch
A: 使用 amend 功能:
/commit --amend
A: 建议先拉取最新变更,然后重新提交:
git pull --rebase origin main
/commit --continue
A: 使用 --skip-<check> 参数:
/commit --skip-lint --skip-test
/review - 代码审查/gen - 代码生成/refactor - 代码重构@GitExpert - Git 专家代理可以在 .gitconfig 中添加快捷别名:
[alias]
cm = "!claude /commit"
cma = "!claude /commit --auto"
cmp = "!claude /commit --push"
cmr = "!claude /commit --review"
在 .commit-config.json 中添加:
{
"customTypes": [
{
"type": "perf",
"description": "性能优化",
"emoji": "⚡"
},
{
"type": "revert",
"description": "回滚提交",
"emoji": "⏪"
}
]
}
创建 .commit-templates/ 目录:
.commit-templates/
├── feature.md
├── bugfix.md
└── hotfix.md
然后在配置中指定:
{
"templates": {
"feature": ".commit-templates/feature.md",
"bugfix": ".commit-templates/bugfix.md"
}
}
让提交变得简单而规范! 🚀