AgentSkillsCN

Commit Conventions

采用标准化的提交信息格式与规范,打造清晰易查、且适配自动化流程的版本控制历史记录。

SKILL.md
--- frontmatter
name: Commit Conventions
description: Standardized commit message formats and conventions for clear, searchable, and automated-friendly version control history.

Commit Conventions

Overview

Commit conventions establish a standard format for commit messages, enabling automated changelog generation, semantic versioning, and clear project history.

Core Principle: "Commits are documentation. Make them readable, searchable, and meaningful."


1. Conventional Commits Standard

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

code
feat(auth): add OAuth2 login support
fix(api): resolve race condition in user creation
docs(readme): update installation instructions

Commit Types

TypeDescriptionExample
featNew featurefeat(payments): add Stripe integration
fixBug fixfix(cart): prevent negative quantities
docsDocumentation onlydocs(api): add endpoint examples
styleCode style (formatting, no logic change)style: fix indentation
refactorCode restructuringrefactor(db): extract query builder
perfPerformance improvementperf(search): add index to user table
testAdd/update teststest(auth): add login flow tests
choreBuild/tooling changeschore: update dependencies
ciCI/CD changesci: add deployment workflow

2. Commit Message Structure

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

<body>

<footer>

Example

code
feat(user-profile): add avatar upload functionality

Users can now upload profile pictures up to 5MB.
Images are automatically resized and optimized.

Closes #123
BREAKING CHANGE: User API now requires multipart/form-data for profile updates

3. Commitlint Configuration

javascript
// commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'chore', 'ci']
    ],
    'subject-case': [2, 'never', ['upper-case']],
    'subject-max-length': [2, 'always', 72],
    'body-max-line-length': [2, 'always', 100]
  }
};

4. Husky Integration

json
// package.json
{
  "scripts": {
    "prepare": "husky install"
  },
  "devDependencies": {
    "@commitlint/cli": "^17.0.0",
    "@commitlint/config-conventional": "^17.0.0",
    "husky": "^8.0.0"
  }
}
bash
# .husky/commit-msg
#!/bin/sh
npx --no -- commitlint --edit $1

5. Semantic Versioning Integration

Commits drive version bumps:

  • feat: → Minor version (1.0.0 → 1.1.0)
  • fix: → Patch version (1.0.0 → 1.0.1)
  • BREAKING CHANGE: → Major version (1.0.0 → 2.0.0)

6. Automated Changelog Generation

bash
# Using standard-version
npx standard-version

# Generates CHANGELOG.md
## [1.2.0] - 2024-01-15
### Features
- **auth**: add OAuth2 login support (#123)
- **payments**: integrate Stripe (#124)

### Bug Fixes
- **cart**: prevent negative quantities (#125)

7. Commit Message Best Practices

Good Commits

code
✅ feat(api): add user search endpoint
✅ fix(auth): resolve token expiration bug
✅ docs: update API documentation

Bad Commits

code
❌ update stuff
❌ fix bug
❌ WIP
❌ asdfasdf

8. Commit Conventions Checklist

  • Format Enforced: Commitlint configured and running?
  • Types Defined: Team agrees on commit types?
  • Scope Guidelines: Scopes documented?
  • Automated Checks: Pre-commit hook validates messages?
  • Changelog: Automated changelog generation set up?
  • Documentation: Convention documented for team?

Related Skills

  • 45-developer-experience/release-workflow
  • 45-developer-experience/lint-format-typecheck