AgentSkillsCN

commit

将各项变更归入逻辑提交,并在提交前与用户逐一确认。

SKILL.md
--- frontmatter
name: commit
description: Group changes into logical commits and confirm each with the user before committing
argument-hint: "[optional message hint]"
disable-model-invocation: true
allowed-tools: Bash, Read, Grep, Glob, AskUserQuestion

Git Status

!git status

Recent Commits (for style reference)

!git log --oneline -5

Staged Diff

!git diff --cached --stat

Unstaged Diff

!git diff --stat

Instructions

Group the current changes into logical, conventional commits. Each commit should be a cohesive unit of work.

Step 1: Analyze and Group

  1. Review all changed, staged, and untracked files above
  2. Read file contents where needed to understand what changed and why
  3. Group files into logical commits — each group should represent one coherent change (e.g., "new feature X", "refactor Y", "update config Z"). Files that were changed together for the same reason belong in the same commit.
  4. Exclude files that look like secrets (.env, credentials) or build artifacts — flag these to the user
  5. Draft a commit message for each group:
    • Short imperative subject line (under 72 chars)
    • Optional body explaining "why" not "what"
  6. If the user provided a hint via $ARGUMENTS, use it to guide grouping and messaging

Step 2: Confirm with User

Present the proposed commits to the user using AskUserQuestion. Show each commit as an option with:

  • The commit message as the label
  • The file list as the description

Ask if they're happy with the grouping, or want to adjust. If there's only one logical commit, still confirm the file list and message.

Step 3: Commit

For each approved commit (in logical order):

  1. Stage only the files for that commit: git add <specific files>
  2. Commit using a HEREDOC:
code
git commit -m "$(cat <<'EOF'
Subject line here

Optional body here.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
EOF
)"
  1. Run git status after the final commit to verify success

IMPORTANT:

  • Never amend existing commits unless explicitly asked
  • Never force push
  • Never skip hooks (no --no-verify)
  • If a pre-commit hook fails, fix the issue and create a NEW commit
  • Always confirm with the user before committing anything