articles

Angular Commit 速查卡

coding
git

We paired with a cutting-edge music API and a team of horticulturalists to build AI-generated playlists that maximize houseplant health.

arrangement-of-windows-by-mike-hindle-unsplash

一、Angular Commit 速查卡(单行记忆)

<type>(<scope>): <subject>                    ← Header(必)
                                             ← 空行
[body]                                       ← 可选,72 字换行
                                             ← 空行
[footer]                                     ← 可选,关联 issue/BREAKING

书写铁律

  1. 英文半角冒号+空格 :
  2. subject ≤ 50 字,首字母小写,句尾无 .
  3. 全部用现在时祈使句:change / add / fix,而非 changed / added / fixed

二、type & scope 枚举字典

type(必须小写)场景解释常见 scope 举例(按需要增删)
feat新功能user, auth, order, payment, cart, goods, coupon, log, config, i18n, api, admin, h5, miniapp
fix修 bug同上 + 具体页面如 login, register, checkout
docs仅文档readme, changelog, api-doc, wiki, comment
style不影响逻辑的格式lint, prettier, css, semicolon, quote
refactor重构service, component, store, util, hook, directive
perf性能优化bundle, img, cache, sql-index, render
test测试相关e2e, unit, jest, cypress, smoke
chore杂务:升级依赖、脚本、构建deps, build, ci, script, docker, webpack, vite
build变更构建系统webpack, rollup, gulp, npm, yarn, pnpm
ci持续集成配置github-actions, jenkins, gitlab-ci, drone
revert回滚一般 scope 用 * 或留空,subject 写 revert: xxx
delete删除功能/文件module, component, api, view
modify功能调整(非新增)同上

特殊 scope

  • * —— 影响全局/多个模块
  • global / common —— 工具、全局配置
  • typo —— 仅错别字,可配合 docs/style

三、Footer 规范

  1. 关联 issue
    Closes #123Fixes #123, #124
  2. 破坏性变更
    BREAKING CHANGE: 旧接口 /foo 已移除,请改用 /v2/foo。
    必须大写且后跟英文冒号,可多空行写详情。
  3. 回滚
    revert: feat(payment): 微信支付功能集成  
    This reverts commit 8f1c3e2.

四、常见坑 & 提示

  1. 一次 commit 只做一件事,混用 feat+fix 会打乱自动生成 CHANGELOG。
  2. 超过 72 字自动换行,否则 GitHub 小屏展示会截断。
  3. 忘记空格 : 或把中文冒号 打进去,husky 钩子会直接拒提。
  4. scope 别太细,否则枚举爆炸;建议团队先统一“模块清单”并写进 README。
  5. 如果项目用 squash merge,feature 分支里可以写“草稿级” message,最终 PR 里再严格按规范重写。
  6. 生成 CHANGELOG 的工具(conventional-changelog/semantic-release)只认 feat/fix/perf/BREAKING,其余 type 默认不计入“特性/修复”章节。
  7. 紧急线上热修,type 仍用 fix,scope 写 hotfix 或 prod,body 里注明“hotfix applied directly on v1.2.3 tag”。