Scripts2026年5月1日·1 分钟阅读

Commitizen — Conventional Commits Made Easy

Commitizen is a CLI tool that guides developers through writing standardized commit messages following the Conventional Commits specification, enabling automated changelogs and semantic versioning.

Introduction

Commitizen provides an interactive prompt that walks developers through composing commit messages that follow a consistent format. By enforcing Conventional Commits, teams can automate changelog generation, semantic versioning, and release workflows without manual bookkeeping.

What Commitizen Does

  • Replaces git commit with an interactive prompt that structures messages by type, scope, and description
  • Enforces Conventional Commits format (feat, fix, chore, docs, etc.) across a team
  • Integrates with adapters like cz-conventional-changelog for customizable commit templates
  • Works alongside commitlint to reject non-conforming commits at the hook level
  • Enables automated CHANGELOG generation and version bumping through tools like standard-version or semantic-release

Architecture Overview

Commitizen is a Node.js CLI that wraps the git commit step. When invoked via git cz or cz, it loads an adapter module that defines the prompt flow and message format. The adapter collects answers through Inquirer.js prompts, assembles a formatted commit message string, and passes it to git commit -m. The tool itself never touches the repository history; it only generates the message.

Self-Hosting & Configuration

  • Install globally via npm or as a project devDependency alongside an adapter
  • Add "config": {"commitizen": {"path": "cz-conventional-changelog"}} to package.json
  • Combine with a prepare-commit-msg or commit-msg git hook via Husky for enforcement
  • Custom adapters can define project-specific commit types, scopes, and validation rules
  • Works in CI by reading commit messages produced during development, not by running interactively

Key Features

  • Interactive CLI prompt eliminates guesswork about commit message format
  • Pluggable adapter system supports Conventional Commits, Jira-linked formats, and custom schemas
  • Seamless integration with Husky, commitlint, and semantic-release for a full automation pipeline
  • Language-agnostic: works on any project that uses git, regardless of tech stack
  • Zero runtime overhead since it only runs at commit time

Comparison with Similar Tools

  • commitlint — validates commit messages but does not provide an interactive prompt
  • semantic-release — automates releases based on commit messages but does not help write them
  • standard-version — generates changelogs from conventional commits but lacks the prompt workflow
  • git-cz — lighter alternative prompt tool, fewer adapter options
  • Changesets — version and changelog management for monorepos with a different commit philosophy

FAQ

Q: Can I use Commitizen without installing it globally? A: Yes. Install it as a devDependency and invoke it via npx cz or add a script in package.json.

Q: Does Commitizen work with monorepos? A: Yes. Scoped commits (e.g., feat(api): ...) let you track changes per package. Pair with Lerna or Changesets for per-package versioning.

Q: How do I enforce Commitizen usage across a team? A: Add a commit-msg hook via Husky that runs commitlint. Developers who forget to use git cz will have non-conforming messages rejected.

Q: Is the Conventional Commits format required? A: No. Commitizen supports pluggable adapters, so you can define any commit message schema your team prefers.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产