Git语义提交备忘单

使用语义前缀提交Git的备忘单

Conventional Commits Cheatsheet

Structure

A conventional commit message follows this structure:

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

Elements

Type (Required)

The type describes the kind of change being made. Common types include:

  • feat: A new feature for the user
  • fix: A bug fix for the user
  • docs: Documentation changes
  • style: Code style changes (formatting, missing semicolons, etc.)
  • refactor: Code changes that neither fix a bug nor add a feature
  • test: Adding or updating tests
  • chore: Maintenance tasks, dependency updates, build changes
  • perf: Performance improvements
  • ci: Changes to CI/CD configuration
  • build: Changes to build system or external dependencies
  • revert: Reverting a previous commit

Scope (Optional)

The scope provides additional context about what part of the codebase is affected:

feat(auth): add OAuth2 integration fix(api): resolve timeout issues docs(readme): update installation instructions 

Description (Required)

A brief description of the change:

  • Use imperative mood (“add” not “added” or “adds”)
  • Keep it concise (50 characters or less recommended)
  • Don’t capitalize the first letter
  • Don’t end with a period

Body (Optional)

Provides more detailed explanation of the change:

  • Separate from description with a blank line
  • Explain the motivation and contrast with previous behavior
  • Use imperative mood

Footer (Optional)

Contains metadata about the commit:

  • Breaking changes: Start with BREAKING CHANGE:
  • Issue references: Closes #123, Fixes #456
  • Co-authors: Co-authored-by: Name <email>

Examples

Simple commit

feat: add user authentication 

With scope

fix(parser): handle edge case in JSON parsing 

With body

feat: add email notifications Users can now receive email notifications for important events. This includes account changes, security alerts, and system updates. 

With footer

fix: prevent racing of requests Introduce a request id and a reference to latest request. Dismiss incoming responses other than from latest request. Closes #123 

Breaking change

feat!: send an email to the customer when a product is shipped BREAKING CHANGE: The shipping service now requires an email address 

Full example

feat(shopping cart): add ability to remove items Users can now remove items from their shopping cart by clicking the remove button next to each item. This improves the user experience by allowing corrections without starting over. Closes #456 Co-authored-by: Jane Doe <jane@example.com> 

Common Tools

Commitizen

Interactive tool for creating conventional commits:

npm install -g commitizen npm install -g cz-conventional-changelog echo '{ "path": "cz-conventional-changelog" }' > ~/.czrc 

Usage:

git cz 

Commitlint

Lints commit messages to ensure they follow conventional format:

npm install --save-dev @commitlint/config-conventional @commitlint/cli 

Configuration in .commitlintrc.json:

{ "extends": ["@commitlint/config-conventional"] } 

Husky

Git hooks to enforce commit message format:

npm install --save-dev husky npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}' 

Semantic Release

Automatically generates releases based on conventional commits:

npm install --save-dev semantic-release 

Conventional Changelog

Generates changelogs from conventional commits:

npm install -g conventional-changelog-cli conventional-changelog -p angular -i CHANGELOG.md -s 

相关工具 (16)

chmod 命令速查表
Linux 权限变更速查表
常用正则表达式备忘单
常用正则表达式模式备忘单。
CSS选择器备忘单
CSS选择器语法备忘单。
Docker Compose 备忘单
Docker Compose 格式备忘单
Docker SWARM 备忘单
Docker Swarm 模式速查表
Dockerfile 备忘单
Dockerfile 语法和构建备忘单
Git 备忘单
Git 是一款分布式版本管理软件。通过这份备忘单,您可以快速访问最常用的 Git 命令。
Git语义提交备忘单
使用语义前缀提交Git的备忘单
JQ备忘单
JQ命令备忘单
JSONPath语法备忘单
JSONPath语法备忘单
Markdown备忘单
Markdown备忘单
Nano备忘单
Nano编辑器备忘单
正则表达式备忘单
JavaScript正则表达式备忘单
Sed 备忘单
sed unix 命令速查表
XPath语法备忘单
XPath语法备忘单
ZPool 备忘单
OpenZFS/ZPool 使用命令和信息
留言区
昵称
邮箱
网址
0/500
0 条评论
Powered by Twikoo v1.6.44
Twikoo 评论管理
密码