Analyzes the current Git changes and automatically generates commit messages that conform to the Conventional Commits specification.
Usage
/git-commit [files...] [options]
Options
| Options | Description |
|---|---|
files... |
Specify the files to commit (optional, defaults to all) |
--all |
Stage all changes and then commit |
--amend |
Amend the previous commit |
--dry-run |
Preview the commit message only, without actually committing |
--no-verify |
Skip Git hooks |
--signoff |
Add a Signed-off-by signature |
--emoji |
Use an emoji prefix |
--type <type> |
Manually specify the commit type (skip inference) |
--scope <scope> |
Manually specify the scope (skip inference) |
Examples
/git-commit # 提交所有暂存的变更
/git-commit src/api.py # 只提交指定文件
/git-commit --all # 暂存所有并提交
/git-commit --dry-run # 预览 commit 消息
/git-commit --emoji --type feat # 带 emoji,指定类型
/git-commit --amend --signoff # 修补上次提交并签名
Execution workflow
Stage 1: Repository validation
[Mode: Check]
- Verify that the current directory is a Git repository
- Detect whether it is in a rebase/merge state
- Get the current branch and HEAD status
Stage 2: Change detection
[Mode: Analysis]
git status # 获取变更状态
git diff --cached # 已暂存的变更
git diff # 未暂存的变更
Processing logic:
- If
files...is specified, only analyze the specified files - If the staging area is empty:
--all→ Executegit add -A- Otherwise, prompt the user to select the files to stage
Stage 3: Smart inference
[Mode: Inference]
Type inference
Automatically infer based on the change content and file paths:
| Type | Trigger condition | Priority |
|---|---|---|
test |
test_*.py, *_test.py, tests/ directory |
1 |
docs |
.md/.rst/.txt files, or only modifying comments/docstrings |
2 |
ci |
.github/, .gitlab-ci.yml, CI configuration |
3 |
build |
pyproject.toml, setup.py, requirements.txt, Dockerfile |
4 |
fix |
Contains the keywords bug/fix/修复/error, or modifications to exception handling | 5 |
feat |
New files, new functions/classes, new API endpoints | 6 |
refactor |
Renaming, extracting functions, structural adjustments that do not change behavior | 7 |
style |
Formatting only, whitespace, semicolon adjustments | 8 |
perf |
Performance optimization, caching, algorithm improvements | 9 |
chore |
Configuration files, utility scripts, miscellaneous items that cannot be categorized | 10 |
Scope inference
Infer based on the directory structure of the changed files:
src/api/users.py → scope: api
src/auth/login.py → scope: auth
tests/test_api.py → scope: api(去掉 tests 前缀)
app/routes/order.py → scope: routes
Rules:
- Take
src/orapp/the first-level directory name under - For a single-file change, the file name can be used as the scope
- When changes span multiple unrelated directories, do not set a scope
Stage 4: Split suggestions
[Mode: Suggestion]
When the following situations are detected, suggest splitting the commit:
- Changes involve 3+ unrelated modules
- Contains both
featandfixtypes of changes - More than 300 changed lines and the logic is unrelated
- Spans multiple top-level directories (source vs documentation vs tests)
Suggested format:
⚠️ 建议拆分为多次提交:
1. feat(auth): 添加 OAuth 登录 → src/auth/oauth.py
2. fix(api): 修复用户查询 bug → src/api/users.py
3. docs: 更新 README → README.md
是否继续合并提交,还是先暂存部分文件?
Stage 5: Breaking Change detection
[Mode: Detection]
Automatically mark BREAKING CHANGE when the following patterns are detected:
- Deleting public functions/classes/methods
- Modifying function signatures (adding/removing parameters, type changes)
- Renaming exported symbols
- Modifying the API return value structure
- Delete configuration item or environment variable
Phase 6: Generate Commit Message
[Mode: Generate]
Format
[emoji] <type>(<scope>): <subject>
[body]
[footer]
Specification
- Subject: ≤ 50 characters, start with a verb, no period
- Verb: add, fix, update, refactor, optimize, delete, remove
- Body: explain the motivation, implementation points, scope of impact (optional)
- Footer: BREAKING CHANGE, related Issue (optional)
Language Detection
Read the most recent 20 commit messages to determine the project's primary language:
- Chinese proportion > 50% → generate Chinese message
- Otherwise → generate English message
Phase 7: Execute Commit
[Mode: Execute]
# 暂存文件(如果指定)
git add <files>
# 写入消息文件
echo "<message>" > .git/COMMIT_EDITMSG
# 执行提交
git commit [-S] [--no-verify] [-s] [--amend] -F .git/COMMIT_EDITMSG
Type and Emoji Mapping
| Emoji | Type | Description |
|---|---|---|
| ✨ | feat |
New feature |
| 🐛 | fix |
Bug fix |
| 📝 | docs |
Documentation update |
| 🎨 | style |
Code formatting |
| ♻️ | refactor |
Code refactoring |
| ⚡️ | perf |
Performance optimization |
| ✅ | test |
Test-related |
| 🔧 | chore |
Build/miscellaneous |
| 👷 | ci |
CI/CD configuration |
| ⏪️ | revert |
Revert commit |
| 🔨 | build |
Build system |
Example Output
Simple feature addition
✨ feat(auth): 添加微信扫码登录
实现微信 OAuth2.0 授权流程,支持绑定已有账户
With Breaking Change
♻️ refactor(api)!: 重构用户接口返回格式
将 user 对象从扁平结构改为嵌套结构,统一响应格式
BREAKING CHANGE: /api/users 接口返回值结构变更
- 原: { id, name, email }
- 新: { data: { id, name, email }, meta: {...} }
Bug fix
🐛 fix(parser): 修复空字符串解析异常
当输入为空字符串时跳过解析,返回默认值
Closes #123
Key Rules
- Git only — do not call package managers or run project code
- Respect hooks — run pre-commit by default,
--no-verifycan be skipped - Do not modify source code — only read the diff, write to
.git/COMMIT_EDITMSG - Atomic commits — one commit does only one thing; complex changes should be split
- Idempotent and safe —
--dry-runproduces no side effects