AgentSkillsCN

commit

采用 Conventional Commits 格式进行 Git 提交工作流。自动分析变更内容、生成提交信息,并妥善处理暂存区操作。

SKILL.md
--- frontmatter
name: commit
description: Git commit workflow with Conventional Commits format. Analyzes changes, generates commit message, handles staging.

Commit Skill

Usage

code
/commit [--type <type>] [--scope <scope>]

Parameters

  • --type: feat | fix | docs | style | refactor | test | chore
  • --scope: Optional scope (e.g., auth, api, ui)

Examples

bash
/commit
/commit --type feat --scope auth
/commit --type fix

Conventional Commits Format

code
<type>(<scope>): <description>

[optional body]

[optional footer]

Types

TypeDescriptionExample
featNew featurefeat(auth): add OAuth2 login
fixBug fixfix(api): handle null response
docsDocumentationdocs: update README
styleFormattingstyle: fix indentation
refactorCode restructurerefactor(utils): extract helper
testTeststest(auth): add login tests
choreMaintenancechore: update dependencies
perfPerformanceperf(db): optimize query
ciCI/CDci: add GitHub Actions
buildBuild systembuild: update webpack config

Scope Examples

  • auth - Authentication
  • api - API layer
  • ui - User interface
  • db - Database
  • config - Configuration

Workflow

Step 1: Analyze Changes

bash
git status
git diff --staged
git diff

Step 2: Determine Type

Based on changes:

  • New functionality → feat
  • Bug fix → fix
  • Only .md files → docs
  • Tests added → test
  • Code cleanup → refactor
  • Dependencies → chore

Step 3: Identify Scope

From changed files:

  • src/auth/* → scope: auth
  • src/api/* → scope: api
  • Multiple areas → no scope

Step 4: Generate Message

markdown
## Changes Detected

### Modified Files
- src/auth/login.ts (+45, -12)
- src/auth/logout.ts (+8, -2)

### Analysis
- Type: feat (new functionality)
- Scope: auth (auth directory)
- Breaking: No

### Suggested Commit

feat(auth): implement session management

  • Add session token generation
  • Implement token refresh logic
  • Add logout with token invalidation

Closes #42

code

Step 5: Execute Commit

bash
git add -A
git commit -m "feat(auth): implement session management

- Add session token generation
- Implement token refresh logic
- Add logout with token invalidation

Closes #42"

Breaking Changes

For breaking changes, add ! and footer:

code
feat(api)!: change response format

BREAKING CHANGE: Response now returns { data, meta } instead of raw data.
Migration: Wrap existing handlers with responseAdapter().

Best Practices

  1. Atomic Commits: One logical change per commit
  2. Present Tense: "add feature" not "added feature"
  3. Imperative: "fix bug" not "fixes bug"
  4. No Period: Don't end subject with period
  5. 50/72 Rule: Subject ≤50 chars, body ≤72 per line

Special Cases

Multiple Types

Split into multiple commits:

bash
/commit  # First: fix the bug
/commit  # Second: add tests for the fix

Work in Progress

code
chore(wip): save progress on feature X

NOT READY FOR REVIEW
- Basic structure done
- Need to add validation

Revert

code
revert: feat(auth): add OAuth2 login

This reverts commit abc1234.
Reason: Breaks legacy clients.

Output

markdown
## Commit Created

**Hash**: abc1234
**Type**: feat
**Scope**: auth
**Message**: implement session management

### Files Committed
- src/auth/login.ts
- src/auth/logout.ts

### Stats
- 2 files changed
- 53 insertions
- 14 deletions