← 返回
未分类 中文

AI Commit Message Generator

Analyze staged changes and generate semantic commit messages automatically. Reads git diff --staged, analyzes code changes, generates conventional commit mes...
分析暂存的更改并自动生成语义化的提交信息。读取 git diff --staged,分析代码更改,生成符合约定的提交信息。
afine907
未分类 clawhub v1.0.0 1 版本 99583.3 Key: 无需
★ 0
Stars
📥 239
下载
💾 0
安装
1
版本
#latest

概述

Commit - Git Commit Generator

Analyze staged changes and generate semantic commit messages.

Commands

CommandDescription
----------------------
/commitAnalyze staged changes and generate commit
/commit -m "message"Commit with custom message
/commit --amendAmend previous commit
/commit --dry-runPreview commit message without committing

Workflow

Step 1: Pre-flight Check

# Verify git repository
git rev-parse --is-inside-work-tree

# Check staged changes
git diff --staged --quiet

# Get staged files
git diff --staged --name-only

If no staged changes: Check git status, prompt user to stage changes first.

Step 2: Analyze Staged Changes

git diff --staged
git diff --staged --stat

Analysis Focus:

  1. Change Type Detection
    • New files → feat
    • Modified files → Based on content
    • Deleted files → refactor or chore
  1. Semantic Type Classification
    • feat: New feature/functionality
    • fix: Bug fix
    • refactor: Code restructuring without behavior change
    • docs: Documentation only
    • style: Formatting, whitespace
    • test: Tests
    • chore: Build, dependencies, tooling
    • perf: Performance improvements
    • ci: CI/CD changes
    • build: Build system changes
  1. Scope Identification
    • Extract from file paths: src/auth/login.ts → scope: auth

Step 3: Generate Commit Message

Format:

<type>(<scope>): <subject>

[optional body]

[optional footer(s)]

Rules:

  • Subject in imperative mood: "add" not "added"
  • No period at end
  • Max 50 characters for subject
  • Body wrap at 72 characters
  • Footer: BREAKING CHANGE:, Closes #123, Fixes #456

Examples:

feat(auth): add JWT token refresh mechanism

fix(payment): handle duplicate callback correctly

Payment callback was processing duplicates due to missing idempotency
check. Added unique constraint on (order_id, callback_id).

Fixes #234

refactor(db)!: migrate from MySQL to PostgreSQL

BREAKING CHANGE: Database migration required.

Step 4: Execute Commit

# Commit with generated message (author is global git user)
git commit -m "type(scope): subject" [-m "optional body"]

Or use heredoc for multi-line:

git commit -m "$(cat <<'EOF'
type(scope): subject

optional body
EOF
)"

Verify:

git log -1 --oneline
git show HEAD --stat

Best Practices

DO:

  • ✅ Analyze ALL staged changes before generating
  • ✅ Use imperative mood ("add" not "added")
  • ✅ Keep subject under 50 characters
  • ✅ Add body for complex changes
  • ✅ Reference issues when applicable
  • ✅ Group related changes in one commit

DON'T:

  • ❌ Commit without staged changes
  • ❌ Mix unrelated changes
  • ❌ Use past tense
  • ❌ End subject with period
  • ❌ Include sensitive information
  • ❌ Skip pre-commit hooks (unless explicitly requested)

Edge Cases

No Staged Changes

git status
# Prompt: "No staged changes. Would you like to stage all changes?"

Empty Repository (Initial Commit)

git rev-parse HEAD 2>/dev/null || git commit -m "chore: initial commit"

Large Diff (>500 lines)

git diff --staged --stat
git diff --staged --unified=1
# Suggest splitting into multiple commits

Merge Conflicts

git status | grep "both modified"
git commit -m "merge: resolve conflicts in <files>"

Hooks Integration

  • pre-commit: Runs automatically
  • commit-msg: Runs automatically
  • If hooks fail: Report error, suggest fixes
  • Bypass with --no-verify only if explicitly requested

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-21 15:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

Performance Profiling

afine907
性能分析速查,用于 Python/Node.js 性能分析、数据库优化和系统性能监控。
★ 0 📥 279

Python Testing

afine907
Python 测试速查:运行 pytest、使用 mock/patch、参数化、fixtures、异步、覆盖率测试。
★ 0 📥 336

Commit Diff Analyzer

afine907
分析两次 Git 提交之间的代码变更。用户提供两个提交 ID 时使用,用于了解两者之间的改动,包括文件修改等。
★ 0 📥 254