AgentSkillsCN

git-commit

使用常规提交消息和质量检查创建 git 提交。当提交更改、生成提交消息,或运行预提交验证时使用。

SKILL.md
--- frontmatter
name: git-commit
description: Create git commits with conventional commit messages and quality checks. Use when committing changes, generating commit messages, or running pre-commit validations.

Smart Git Commit

Create meaningful git commits with conventional commit messages and quality checks.

When to Use

  • Committing staged or unstaged changes
  • Generating conventional commit messages
  • Running pre-commit quality checks
  • Ensuring consistent commit message format

Pre-Commit Quality Checks

Before committing, verify:

CheckCommandPurpose
Buildnpm run build / dotnet buildEnsure code compiles
Testsnpm test / dotnet testVerify functionality
Lintnpm run lint / eslint .Check code style
Typestsc --noEmitValidate TypeScript

Workflow

1. Check Repository Status

bash
# View current status
git status

# View staged changes
git diff --cached

# View unstaged changes
git diff

# View changed files summary
git diff --stat

2. Stage Changes

bash
# Stage specific files
git add path/to/file.ts

# Stage all modified tracked files
git add -u

# Stage all changes (careful with new files)
git add -A

# Interactive staging
git add -p

3. Analyze Changes

Determine from the diff:

  • What files were modified
  • Nature of changes (feature, fix, refactor, etc.)
  • The scope/component affected
  • Impact and purpose

4. Create Commit

bash
# Commit with message
git commit -m "type(scope): subject"

# Commit with body
git commit -m "type(scope): subject" -m "Detailed body explanation"

# Open editor for message
git commit

Conventional Commit Format

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

<body>

<footer>

Types

TypeUse ForExample
featNew featurefeat(auth): add JWT token refresh
fixBug fixfix(api): handle null response
docsDocumentationdocs(readme): update install steps
styleFormatting onlystyle: fix indentation
refactorCode restructurerefactor(utils): extract helper
testTest changestest(auth): add login tests
choreMaintenancechore(deps): update packages
buildBuild systembuild: update webpack config
ciCI/CD changesci: add deploy workflow
perfPerformanceperf(query): add index lookup

Scope (Optional)

The component or area affected:

  • auth, api, ui, db, config
  • Feature names: login, checkout, dashboard
  • Layer names: service, controller, model

Subject Rules

  • Use imperative mood: "add" not "added" or "adds"
  • Lowercase first letter
  • No period at end
  • Max 50 characters
  • Be specific and meaningful

Body (Optional)

  • Explain why, not what (the diff shows what)
  • Wrap at 72 characters
  • Separate from subject with blank line

Footer (Optional)

  • Breaking changes: BREAKING CHANGE: description
  • Issue references: Fixes #123, Closes #456

Examples

Simple Feature

bash
git commit -m "feat(cart): add quantity selector"

Bug Fix with Context

bash
git commit -m "fix(auth): prevent token expiry during refresh

The refresh token was being invalidated before the new token
was issued, causing a race condition on slow connections.

Fixes #234"

Breaking Change

bash
git commit -m "refactor(api)!: change response format to JSON:API

BREAKING CHANGE: API responses now follow JSON:API spec.
All clients must update their response parsing logic.

Migration guide: docs/migration-v2.md"

Multiple Scopes

bash
git commit -m "feat(auth,api): add role-based access control"

Message Patterns by Change Type

New Files Added

bash
# New feature file
feat(module): add user preferences service

# New test file
test(auth): add unit tests for login flow

# New config file
chore(config): add production environment settings

Files Modified

bash
# Bug fix
fix(parser): handle empty input gracefully

# Enhancement
feat(search): add fuzzy matching support

# Refactor
refactor(utils): simplify date formatting logic

Files Deleted

bash
# Remove deprecated code
chore: remove legacy authentication module

# Clean up
refactor(api): remove unused endpoints

Dependency Changes

bash
# Update dependencies
chore(deps): update lodash to 4.17.21

# Add new dependency
chore(deps): add zod for schema validation

# Remove dependency
chore(deps): remove moment.js in favor of date-fns

Quick Reference

bash
# View what will be committed
git diff --cached --stat

# Amend last commit (unpushed only)
git commit --amend

# Amend without changing message
git commit --amend --no-edit

# View recent commits
git log --oneline -5

Restrictions

  • Do NOT add "Co-authored-by" or AI signatures
  • Do NOT include "Generated with" messages
  • Do NOT modify git configuration
  • Do NOT use emojis in commit messages
  • Use only existing git user configuration