Conventional Commits

作者 patricio0312rev79ea6af48569无许可证62 个星标收录于 2026年10月8日更新于 2026年10月8日仓库8个月前更新

Generates semantic commit messages following the Conventional Commits specification with proper types, scopes, breaking changes, and footers. Use when users request "write commit message", "conventional commit", "semantic commit", or "format commit".

AI 生成的概览

按照 Conventional Commits 规范撰写提交信息,包含类型、范围、破坏性变更标记与页脚。

功能
提供遵循 Conventional Commits 规范生成标准化语义化提交信息的参考与流程。内容涵盖提交类型及其对 SemVer 的影响、范围约定、破坏性变更写法、正文与页脚标记,以及正反示例。还展示了与 commitlint、Husky 和 semantic-release 的可选集成,并以生成信息的检查清单收尾。
适用场景
当用户要求撰写、格式化或审查提交信息,或需要语义化/约定式提交时使用。也适用于制定提交信息规范或配置依赖该规范的工具。
运行要求
无需脚本或软件包,仅为说明性内容。文中提到的工具(commitlint、Husky、semantic-release)为可选项,若实际安装则需要 Node.js 与 npm。

Conventional Commits

Write standardized, semantic commit messages that enable automated versioning and changelog generation.

Core Workflow

  1. Analyze changes: Review staged files and modifications
  2. Determine type: Select appropriate commit type (feat, fix, etc.)
  3. Identify scope: Optional component/module affected
  4. Write description: Concise summary in imperative mood
  5. Add body: Optional detailed explanation
  6. Include footer: Breaking changes, issue references

Commit Message Format

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

Commit Types

TypeDescriptionSemverExample
featNew featureMINORfeat: add user authentication
fixBug fixPATCHfix: resolve login redirect loop
docsDocumentation only-docs: update API reference
styleFormatting, whitespace-style: fix indentation in utils
refactorCode change, no feature/fix-refactor: extract validation logic
perfPerformance improvementPATCHperf: optimize database queries
testAdding/fixing tests-test: add unit tests for auth
buildBuild system, dependencies-build: upgrade to Node 20
ciCI/CD configuration-ci: add GitHub Actions workflow
choreMaintenance tasks-chore: update .gitignore
revertRevert previous commit-revert: undo feature flag change

Scopes

Scopes indicate the area of the codebase affected:

bash
# Component/module scopesfeat(auth): add OAuth2 supportfix(api): handle timeout errorsdocs(readme): add installation steps
# File-based scopesstyle(eslint): update linting rulesbuild(docker): optimize image size
# Layer scopesrefactor(service): extract user servicetest(e2e): add checkout flow tests

Breaking Changes

Mark breaking changes with ! or BREAKING CHANGE footer:

bash
# Using ! notationfeat(api)!: change response format to JSON:API
# Using footerfeat(api): change response format
BREAKING CHANGE: Response now follows JSON:API specification.Clients must update their parsers.

Commit Message Examples

Simple Feature

feat: add dark mode toggle

Feature with Scope

feat(ui): add dark mode toggle to settings page

Bug Fix with Issue Reference

fix(auth): resolve session expiration race condition
The session refresh was racing with the expiration check,causing intermittent logouts.
Fixes #234

Breaking Change

feat(api)!: migrate to v2 response format
BREAKING CHANGE: All API responses now use camelCase keysinstead of snake_case. Update client parsers accordingly.
Migration guide: https://docs.example.com/v2-migration

Multiple Footers

fix(payments): correct tax calculation for EU customers
Updated tax calculation to use customer's billing countryinstead of shipping country for digital goods.
Fixes #456Reviewed-by: AliceCo-authored-by: Bob <[email protected]>

Revert Commit

revert: feat(auth): add OAuth2 support
This reverts commit abc123def456.
Reason: OAuth provider has rate limiting issues in production.Will re-implement with proper caching.

Description Guidelines

Do

  • Use imperative mood: "add" not "added" or "adds"
  • Keep under 72 characters
  • Start with lowercase
  • No period at the end
  • Be specific and concise

Don't

  • "Fixed bug" (too vague)
  • "Updated stuff" (not descriptive)
  • "WIP" (commit when ready)
  • "misc changes" (split into separate commits)

Good Examples

bash
feat: add email verification flowfix: prevent duplicate form submissionsrefactor: extract payment processing to serviceperf: cache user preferences in memorydocs: add API authentication examples

Bad Examples

bash
# Too vaguefix: fixed itupdate: updates
# Wrong tensefeat: added new featurefix: fixes the bug
# Too longfeat: add a new feature that allows users to export their data in multiple formats including CSV, JSON, and XML

Body Guidelines

When to include a body:

  • Changes need context or explanation
  • Complex logic that isn't self-evident
  • Breaking changes require migration info
  • Multiple related changes in one commit
fix(cache): invalidate user cache on profile update
Previously, profile updates were not reflected until cache expiry.This caused confusion when users updated their avatar and didn'tsee the change immediately.
The fix adds cache invalidation after successful profile updatesand ensures CDN purge for static assets.

Footer Tokens

TokenPurposeExample
FixesCloses issueFixes #123
ClosesCloses issueCloses #456
RefsReferences issueRefs #789
BREAKING CHANGEBreaking changeBREAKING CHANGE: description
Reviewed-byReviewer creditReviewed-by: Name
Co-authored-byCo-author creditCo-authored-by: Name <email>

Integration with Tooling

Commitlint Configuration

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

Husky Pre-commit Hook

bash
# .husky/commit-msg#!/bin/sh. "$(dirname "$0")/_/husky.sh"npx --no-install commitlint --edit "$1"

Package.json Setup

json
{  "devDependencies": {    "@commitlint/cli": "^18.0.0",    "@commitlint/config-conventional": "^18.0.0",    "husky": "^8.0.0"  },  "scripts": {    "prepare": "husky install"  }}

Semantic Release Integration

Conventional commits enable automated versioning:

yaml
# .releaserc.ymlbranches:  - mainplugins:  - "@semantic-release/commit-analyzer"  - "@semantic-release/release-notes-generator"  - "@semantic-release/changelog"  - "@semantic-release/npm"  - "@semantic-release/git"

Version Bumping Rules

Commit TypeVersion BumpExample
featMinor (0.X.0)1.2.0 → 1.3.0
fixPatch (0.0.X)1.2.0 → 1.2.1
perfPatch (0.0.X)1.2.0 → 1.2.1
BREAKING CHANGEMajor (X.0.0)1.2.0 → 2.0.0
OthersNo bump1.2.0 → 1.2.0

Commit Message Generator

When analyzing changes, generate a commit message:

bash
# 1. Check staged changesgit diff --cached --name-only
# 2. Analyze change type# - New files = likely feat# - Modified test files = test# - Modified docs = docs# - Bug-related keywords = fix
# 3. Identify scope from path# src/components/Button.tsx → components or ui# src/services/auth.ts → auth or services
# 4. Generate messagefeat(ui): add loading state to Button component

Best Practices

  1. One logical change per commit: Don't mix features with fixes
  2. Commit early, commit often: Small, focused commits
  3. Write for reviewers: Messages should explain why, not just what
  4. Reference issues: Link to tickets/issues when applicable
  5. Use scopes consistently: Establish team conventions
  6. Review before committing: git diff --cached to verify changes

Output Checklist

Every commit message should:

  • Start with valid type (feat, fix, docs, etc.)
  • Use imperative mood in description
  • Keep description under 72 characters
  • Include scope when applicable
  • Mark breaking changes with ! or footer
  • Reference related issues in footer
  • Provide body for complex changes
  • Follow team's scope conventions

来源与署名

来源:patricio0312rev/skills位于foundation/conventional-commits提交79ea6af

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架