Git Commit Message 全局安装
开发环境
- 电脑系统: Windows 10 64位系统
- 调试工具: PowerShell, Git, cnpm
Commit Message 格式
使用 Angular 团队的规范,其Commit Message格式为:
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
大致分为三个部分:
- 标题行(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, 效果如下:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190703204712424.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xhbmhhaXh1YW52dg==,size_16,color_FFFFFF,t_70)
使用 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 命令
效果如图所示:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190703204738340.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xhbmhhaXh1YW52dg==,size_16,color_FFFFFF,t_70)
项目文件中会自动生成 CHANGELOG.md 文件
参考链接
- Developing AngularJS
- 优雅的提交你的 Git Commit Message
- commitizen
- standard-version