Commit message全局安装

Git Commit Message 全局安装

开发环境

  1. 电脑系统: Windows 10 64位系统
  2. 调试工具: PowerShell, Git, cnpm

Commit Message 格式

使用 Angular 团队的规范,其Commit Message格式为:

(): 



大致分为三个部分:

  • 标题行(header): 必填, 描述主要修改类型和内容
  • 主题内容(boby): 描述为什么修改, 做了什么样的修改, 以及开发的思路等等
  • 页脚注释(footer): 放 Breaking Changes 或 Closed Issues

由如下部分构成:

  • type: commit 的类型
  • scope: scope可以是指定提交更改位置的任何内容
  • subject: subject包含对变化的简洁描述
  • body: commit 具体修改内容
  • feat: 新功能
  • fix: 修复bug
  • docs: 文档修改
  • style: 代码格式修改
  • refactor: 代码重构
  • perf: 性能提供的修改
  • test: 测试
  • chore: 其他修改, 比如构建流程, 依赖管理
  • footer: 一些备注, 通常是 BREAKING CHANGE 或修复的 bug 的链接

使用 commitizen、cz-conventional-changelog代替git commit

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

在项目中执行 git cz 或者 npm run commit, 效果如下:
Commit message全局安装_第1张图片

使用 standard-version自动生成 CHANGELOG

cnpm i -g standard-version

在项目目录添加 .versionrc 或者 .versionrc.json 文件, 文件内容:

{
  "types": [
    {"type":"feat", "section":"Features"},
    {"type":"fix", "section":"Bug Fixes"},
    {"type":"docs", "section":"Others"},
    {"type":"style", "hidden":true},
    {"type":"refactor", "hidden":true},
    {"type":"perf", "hidden":true},
    {"type":"test", "section":"Tests", "hidden":false},
    {"type":"build", "section":"Build System", "hidden":false},
    {"type":"ci", "hidden":true},
    {"type":"chore", "section":"Chores", "hidden":false},
    {"type":"revert", "section":"BREAKING CHANGES", "hidden":false}
  ]
}

使用 standard-version 命令

效果如图所示:
Commit message全局安装_第2张图片

项目文件中会自动生成 CHANGELOG.md 文件

参考链接

  1. Developing AngularJS
  2. 优雅的提交你的 Git Commit Message
  3. commitizen
  4. standard-version

你可能感兴趣的:(工具使用与配置)