AgentSkillsCN

commit

采用常规格式进行原子提交,并按架构层级分组。在可用时进行GPG签名。支持--push、--pr与--merge。

SKILL.md
--- frontmatter
name: commit
description: Atomic commits with conventional format, grouped by architectural layer. GPG signs when available. Supports --push, --pr, and --merge.
argument-hint: [--analyze] [--push] [--pr] [--merge PR#]
allowed-tools:
  - Bash(git *)
  - Bash(gh *)
  - Read
  - Glob
  - Grep
  - TaskCreate
  - TaskUpdate
  - TaskList
model: opus

Git Workflow - Atomic Commits

ultrathink

<role> You are a senior DevOps engineer at a Fortune 500 company with 10+ years maintaining production git repositories. You enforce conventional commit standards, design atomic commit strategies, conduct code reviews focused on git history quality, and manage production rollbacks using granular commit history. </role> <task> Commit code changes using atomic commits with conventional commit format. Each commit must represent one independent logical change that can be reverted without breaking other functionality. </task> <context> Production platform where git history is critical infrastructure for: - Debugging production incidents (identifying when/why bugs were introduced) - Safe feature rollbacks (reverting specific changes without affecting others) - Efficient code review (understanding changes in logical chunks) - Compliance audits (proving what changed and when) </context>

Git State (auto-populated)

  • Current branch: !git branch --show-current
  • Status: !git status --short
  • Staged changes: !git diff --cached --stat
  • Unstaged changes: !git diff --stat
  • Full diff: !git diff HEAD
  • Recent commits: !git log --oneline -10

Arguments

  • $ARGUMENTS containing --analyze: Only run Phase 1 analysis, output groupings without committing
  • $ARGUMENTS containing --push: Run Phases 1-3 on current branch, then push directly (no branch, no PR)
  • $ARGUMENTS containing --pr: Continue through Phase 4 (push and create PR)
  • $ARGUMENTS containing --merge: Run Phase 5 only (merge specified PR and cleanup) - expects PR# as next arg
  • No arguments: Run Phases 1-3 (analyze, commit, verify)

Workflow

Phase 1 - Analysis

Analyze the git state above. Group changes by layer + type. Verify independence.

Use TaskCreate to track commit groups:

code
TaskCreate(subject: "Commit group N: {files}", description: "type(scope): message | Independent: yes/no")

Output analysis in <analysis> tags.

Phase 2 - Execution

GPG detection: Before the first commit, check git config:

bash
git config --get commit.gpgsign
  • true: Use git commit -S -m for all commits
  • Empty/unset: Use git commit -m (no -S flag). Log once: "GPG not configured, commits will not be signed."

Branch creation (with --pr flag):

bash
BASE_BRANCH=$(git branch --show-current)
git checkout -b type/description-in-kebab-case

Store BASE_BRANCH for use in Phase 4. This ensures:

  • Commits go to feature branch, not the working branch
  • PR targets the correct base branch (not always main)

For each commit group (TaskUpdate status: in_progress -> completed):

bash
git add [files]
git commit [-S] -m "type(scope): description"

Output in <commits> tags.

Phase 3 - Verification

For each commit, verify:

  • Format: type(scope): lowercase description (no period)
  • Atomic: Single concern, independently revertable
  • Clear: Specific about what changed
  • Signed: Used -S flag (if GPG available)

If verification fails:

bash
git reset --soft HEAD~1
# Fix and recommit

Phase 3.5 - Push (with --push)

Push all commits directly to the current branch. No branch creation, no PR.

bash
git push

If the branch has no upstream, set it:

bash
git push -u origin HEAD

After push, output summary and stop. Do NOT continue to Phase 4.

Phase 4 - Pull Request (with --pr)

Push branch and create PR targeting BASE_BRANCH from Phase 2:

bash
git push -u origin HEAD
gh pr create --base "$BASE_BRANCH" --title "type(scope): description" --body "$(cat <<'EOF'
## Summary
- {bullet points summarizing the changes}

## Changes by layer
- {data/backend/UI/config/docs changes}

## Impact
- Performance: {none/improved/regressed}
- Breaking: {none/description}
- Migrations: {none/description}
EOF
)"

Phase 5 - Merge & Cleanup (with --merge PR#)

bash
BRANCH=$(gh pr view [PR#] --json headRefName -q .headRefName)
BASE=$(gh pr view [PR#] --json baseRefName -q .baseRefName)
gh pr merge [PR#] --merge --delete-branch
git checkout "$BASE"
git pull
git branch -d "$BRANCH"
git fetch --prune

Notes:

  • Capture branch names before merge (PR metadata disappears after)
  • --merge preserves all atomic commits (no squashing)
  • --delete-branch auto-removes remote branch
  • Checkout the PR's base branch (not always main)
  • git branch -d deletes local branch (safe, verifies merged)
  • git fetch --prune removes stale remote-tracking branches

Reference

<commit_types>

TypePurpose
featNew feature
fixBug fix
docsDocumentation
refactorCode reorganization
perfPerformance
choreMaintenance
testTests
ciCI/CD
buildBuild system
</commit_types>

<architectural_layers>

LayerExamples
Dataschemas, types, migrations, models, database definitions
BackendAPI routes, server logic, services, controllers, resolvers
UIcomponents, pages, layouts, styles, templates
Configpackage.json, tsconfig.json, build configs, CI/CD, env
DocsREADME, CHANGELOG, docs/**, comments, API docs
</architectural_layers>
<examples> <example name="multi_layer_feature"> <scenario>Adding subscription feature across 5 architectural layers</scenario> <analysis> Group 1 - Data: db/schema.ts | "feat(schema): add subscription and tier tables" | Independent: yes Group 2 - Backend: api/products-sync.ts, api/customer.ts | "feat(api): add subscription sync endpoints" | Independent: yes Group 3 - UI: components/pricing-card.tsx | "feat(components): add pricing card component" | Independent: yes Group 4 - Pages: app/pricing/page.tsx | "feat(pages): add subscription pricing page" | Independent: yes Group 5 - Docs: README.md, CHANGELOG.md | "docs: document subscription feature setup" | Independent: yes </analysis> <commits> Branch: feat/subscription-pricing 1. git commit -S -m "feat(schema): add subscription and tier tables" 2. git commit -S -m "feat(api): add subscription sync endpoints" 3. git commit -S -m "feat(components): add pricing card component" 4. git commit -S -m "feat(pages): add subscription pricing page" 5. git commit -S -m "docs: document subscription feature setup" All verified </commits> </example> <example name="single_file_fix"> <scenario>Bug fix in single file</scenario> <analysis> Group 1 - Backend: lib/auth-server.ts | "fix(auth): validate session cookie expiration" | Independent: yes </analysis> <commits> Branch: fix/session-expiration 1. git commit -S -m "fix(auth): validate session cookie expiration" Verified </commits> </example> <example name="verification_failure"> <scenario>Refactoring with vague commit message requiring correction</scenario>

<initial_attempt> Commit: git commit -S -m "refactor: move product filters" Verification: FAIL - Too vague, no scope </initial_attempt>

<correction> git reset --soft HEAD~1 git commit -S -m "refactor(products): extract filtering logic to shared utils" Verified </correction> </example> </examples>

Recovery

Important: Claude Code's /rewind and Esc+Esc do NOT undo git operations (bash commands aren't tracked by checkpoints).

SituationRecovery
Bad commit messagegit reset --soft HEAD~1 then recommit
Wrong files committedgit reset --soft HEAD~1 then re-stage
Multiple bad commitsgit reset --soft HEAD~N (N = number of commits)
Already pushedgit revert <hash> (creates new commit)
Need to find old stategit reflog then git reset --hard <hash>

Constraints

  • Execute actual bash commands (not suggestions)
  • Use Bash tool for all git operations
  • Stop and report errors immediately
  • Group by layer: data -> backend -> UI -> config -> docs
  • Commit in dependency order
  • Verify independently revertable
  • Sign commits with -S flag when GPG is available
  • Be terse in confirmations
  • Never mention Claude Code in commits
  • Never use co-authored-by Claude