四时宝库

程序员的知识宝库

git规范语义提交消息,变得有意义

更多互联网精彩资讯、工作效率提升关注【飞鱼在浪屿】(日更新)


对提交消息样式的微小更改使您成为更好的程序员。

格式: <type>(<scope>): <subject>

<scope> 是可选的


例子

feat: add hat wobble
^--^  ^------------^
|     |
|     +-> Summary in present tense.
|
+-------> Type: chore, docs, feat, fix, refactor, style, or test.

更多例子:

  • feat:(用户的新功能,不是构建脚本的新功能)
  • fix:(用户的错误修复,而不是构建脚本的修复)
  • docs:(对文档的更改)
  • style:(格式化、缺少分号等;没有更改生产代码)
  • refactor:(重构生产代码,例如重命名变量)
  • test:(添加缺失的测试,重构测试;没有生产代码更改)
  • chore:(更新 grunt 任务等;没有更改生产代码)
  • perf:提高性能的代码更改

自动化检查规范

结合这个规范,做一个git提交前的hook脚本

#!/bin/sh
branch="$(git rev-parse --abbrev-ref HEAD)";
commit_regex='((CDW-)([1-9][0-9])|((feat|fix|chore|refactor|style|test|docs)(((\w{0,15})))?))(:.\S.*)';
error_msg="Aborting commit. Your commit message format is invalid, please check the references."
commit_message="$1";
if ! grep -iqE "$commit_regex" <<<"${commit_message}"; then
echo "$error_msg" >&2
exit 1
fi
if [ "$branch" = "master" ]; then
echo "You can't commit directly to master branch"
exit 1
fi
if [ "$branch" = "develop" ]; then
echo "You can't commit directly to develop branch"
exit 1
fi

更多:

了解规范:

https://www.conventionalcommits.org/en/v1.0.0/#summary

这里有大神们的讨论

https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言
    友情链接