美文网首页
git hooks 检查commit message

git hooks 检查commit message

作者: 阿福德 | 来源:发表于2019-02-19 10:48 被阅读0次

我们有时候想要规范git提交信息,幸好git提供了钩子,我们可以利用这个钩子类检查git 提交信息。
只需要如下两个步骤:

  1. 在.git/hooks目录下找到commit-msg.sample,重命名为commit-msg
  2. 修改其内容为如下:
#!/bin/sh
MSG=`awk '{printf("%s",$0)}' $1`
if [ ${#MSG} -lt 10 ]  
  then
    echo "-------------------------------------------------------------------"
    echo "commit message 只有${#MSG}字符"
    echo "message的长度不能小于10, 本次提交失败,请完善commit message,再提交"
    echo "-------------------------------------------------------------------"
    exit 1
fi

如果这个hook返回非零,则表示git commit 命令就不会执行成功。

相关文章

网友评论

      本文标题:git hooks 检查commit message

      本文链接:https://www.haomeiwen.com/subject/mgrxyqtx.html