运行时依赖
版本
git diff --staged --quiet
安装命令
点击复制本土化适配说明
AI Commit Message Generator — AI Commit Message 生成器 安装说明: 安装命令:["openclaw skills install ai-commit"]
技能文档
Commit - Git Commit 生成器
Analyze staged changes and 生成 semantic commit messages.
Commands Command Description /commit Analyze staged changes and 生成 commit /commit -m "message" Commit with custom message /commit --amend Amend previous commit /commit --dry-运行 Preview commit message without committing 工作流 Step 1: Pre-flight 检查 # 验证 git 仓库 git rev-解析 --is-inside-work-tree
# 检查 staged changes git diff --staged --quiet
# 获取 staged files git diff --staged --name-only
If no staged changes: 检查 git 状态, prompt user to stage changes first.
Step 2: Analyze Staged Changes git diff --staged git diff --staged --stat
Analysis Focus:
Change Type 检测ion
New files → feat Modified files → Based on content 删除d files → refactor or chore
Semantic Type Classification
feat: New feature/functionality fix: Bug fix refactor: Code restructuring without behavior change docs: Documentation only style: 格式化ting, whitespace test: Tests chore: Build, dependencies, 工具ing perf: Performance improvements ci: CI/CD changes build: Build 系统 changes
Scope Identification
提取 from file paths: src/auth/记录in.ts → scope: auth Step 3: 生成 Commit Message
格式化:
():
[optional body]
[optional footer(s)]
Rules:
Subject in imperative mood: "添加" not "添加ed" No period at end Max 50 characters for subject Body wrap at 72 characters Footer: BREAKING CHANGE:, Closes #123, Fixes #456
Examples:
feat(auth): 添加 JWT 令牌 refresh mechanism
fix(payment): handle duplicate callback correctly
Payment callback was processing duplicates due to missing idempotency 检查. 添加ed unique constrAInt on (order_id, callback_id).
Fixes #234
refactor(db)!: 迁移 from MySQL to PostgreSQL
BREAKING CHANGE: Database 迁移 required.
Step 4: 执行 Commit # Commit with 生成d 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 )"
验证:
git 记录 -1 --oneline git show HEAD --stat
Best Practices
DO:
✅ Analyze ALL staged changes before generating ✅ Use imperative mood ("添加" not "添加ed") ✅ Keep subject under 50 characters ✅ 添加 body for complex changes ✅ Reference issues when 应用licable ✅ Group related changes in one commit
DON'T:
❌ Commit without staged changes ❌ Mix unrelated changes ❌ Use past tense ❌ End subject with period ❌ Include sensitive in格式化ion ❌ Skip pre-commit hooks (unless explicitly 请求ed) Edge Cases No Staged Changes git 状态 # Prompt: "No staged changes. Would you like to stage all changes?"
Empty 仓库 (Initial Commit) git rev-解析 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 状态 | grep "机器人h modified" git commit -m "merge: resolve conflicts in "
Hooks Integration pre-commit: 运行s automatically commit-msg: 运行s automatically If hooks fAIl: 报告 error, suggest fixes Bypass with --no-验证 only if explicitly 请求ed