git

Git Commit Log提交规范

2020-12-02  本文已影响0人  但时间也偷换概念

commit log规范的意义:

commit message格式 :

<type>(<scope>): <subject>
<body>
<footer>

type(必须)

用于说明git commit的类别,只允许使用下面的标识。

feat:新功能(feature)。

fix/to:修复bug,可以是QA发现的BUG,也可以是研发自己发现的BUG。

docs:文档(documentation)。

style:格式(不影响代码运行的变动)。

refactor:重构(即不是新增功能,也不是修改bug的代码变动)。

perf:优化相关,比如提升性能、体验。

test:增加测试。

chore:构建过程或辅助工具的变动。

revert:回滚到上一个版本。

merge:代码合并。

sync:同步主线或分支的Bug。

scope(可选)

scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。

例如在Angular,可以是location,browser,compile,compile,rootScope, ngHref,ngClick,ngView等。如果你的修改影响了不止一个scope,你可以使用*代替。

subject(必须)

subject是commit目的的简短描述,不超过50个字符。

建议使用中文(感觉中国人用中文描述问题能更清楚一些)。

fix(DAO):用户查询缺少username属性 
feat(Controller):用户查询接口开发

body(可选)

改动内容多的话,可以换行继续描述详细改动

footer(可选)

有不兼容场景用Breaks结尾。

feat($browser): onUrlChange event (popstate/hashchange/polling)
Added new event to $browser:
- forward popstate event if available
- forward hashchange event if popstate not available
- do polling when neither popstate nor hashchange available
Breaks $browser.onHashChange, which was removed (use onUrlChange instead)

commit log hook

shell

在本地.git/hooks/文件夹, commit-msg.sample 改名为commit-msg。

image.png

然后sudo vim把以下shell copy到commit-msg。

#!/bin/sh

COMMIT_MSG=`cat $1 | egrep "^(feat|fix|docs|chore)\(\w+\)?:\s(\S|\w)+"`

if [ "$COMMIT_MSG" = "" ]; then
  echo "Commit Message 不规范,请检查!\n"
  exit 1
fi

if [ ${#COMMIT_MSG} -lt 15 ]; then
  echo "Commit Message 太短了,请再详细点!\n"
  exit 1
fi

commit

不规范提交:header填写xx(util)试试

image.png

maven

也可以用maven plugin动态生成shell,这样可以持久化check功能到git。

上一篇 下一篇

猜你喜欢

热点阅读