SuperAPI AI Directory

git-commit

General & other

View repository

Updated 10-16 09:44

About this skill

Git Commit - Smart Commit Assistant

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]

  1. Verify that the current directory is a Git repository
  2. Detect whether it is in a rebase/merge state
  3. 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 → Execute git 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/ or app/ 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 feat and fix types 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

  1. Git only — do not call package managers or run project code
  2. Respect hooks — run pre-commit by default,--no-verify can be skipped
  3. Do not modify source code — only read the diff, write to .git/COMMIT_EDITMSG
  4. Atomic commits — one commit does only one thing; complex changes should be split
  5. Idempotent and safe — --dry-run produces no side effects