优化 Git Commit Message

git-logo

目前不少项目都是经过 Git 进行管理的,Git 每次提交代码的过程当中 提交说明 commit message 是必须的。但仅仅必须是不够的,好的提交说明能够帮助咱们提升项目的总体质量。git

做用与优势

提交说明最首要的目的是帮助 提交者 说明本次提交的目的,而规范的说明信息有几个好处。github

  1. 提供完整的信息,帮忙快速定位问题
  2. 过滤某些 commit ,快速查找有用信息
  3. 直接从 commit 信息生成 Change log
  4. 加快 Code Review 的过程

基本要求

  • 第一行应该少于 50 个字。随后是一个空行
  • 永远不在 git commit 上增长 -m <msg> 或者 --message=<msg> 参数,而须要单独写提交信息

好的提交说明要包含下面的内容:shell

  1. 为何要提交此次修改?
  2. 怎么解决的问题?
  3. 可能影响哪些内容?

Angular 规范 CommitMsg 格式

Angular 主要有三个格式,其中 Head 是必须的,bodyfooter 是可选的。app

# head: <type>(<scope>): <subject>
# - type: feat, fix, docs, style, refactor, test, chore
# - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)
# - subject: start with verb (such as 'change'), 50-character line
#
# body: 72-character wrapped. This should answer:
# * Why was this change necessary?
# * How does it address the problem?
# * Are there any side effects?
#
# footer: 
# - Include a link to the ticket, if any.
# - BREAKING CHANGE
#

其中 type 用来讲明 commit 的类别,只容许使用下面的 7 个标识。ide

  • feat 新功能
  • fix 修补 bug
  • docs 文档
  • style 格式
  • refactor 重构
  • test 增长测试
  • chore 构建过程、辅助工具
  • perf 提升性能

若是 typefeatfix ,则该 commit 信息将确定出如今 change log 之中。工具

scope 用于说明 commit 影响的范围,好比影响哪一层、哪一个包中的内容或者使用哪些方案的实例。性能

subject 是关于 commit 信息的简短描述,不超过 50 个字。测试

Body

Body 部分是针对本次 commit 的详细描述,能够多行,要表达清楚变更的动机、与以前行为的对比。this

用于不兼容变更和关闭 Issue 。spa

使用 gitemoji 进行美化

虽然纯文字的提交说明已经很是明确了,可是却比较单调,并且在一些内容上感受少了一些步骤,因而在现有的内容上进行少许的修改以更美观的清晰。

type 主要将原来的 chore 进行了拆分,增长了 cireview 两个内容,用来补充项目开发过程当中的流程。其它的还有一些内容,能够参照 gitemoji

  • feat 新功能 :sparkles:
  • fix 修补 bug :bug: 🐛
  • docs 文档 :memo: 📝
  • style 格式 :art: 🎨
  • refactor 重构 :recycle:
  • test 增长测试 :white_check_mark:
  • ci 持续集成 :construction_Worker: 👷
  • review 完成 review :ok_hand: 👌
  • perf 提升性能 :zap:

相关工具

其它

使用 git log 查询的时候,看到的内容比较简单,能够经过下面的命令将信息格式化输出。

alias lg="git log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(red)%h%C(r) —— %C(bold blue)%an%C(r): %C(white)%s%C(r) %C(dim white) %C(bold green)(%ar)%C(r) %C(bold yellow)%d%C(r)' --all"

使用命名查询的效果以下:

lg.png

相关文章
相关标签/搜索