如 this 中所述回答,可以在 Github 提交中引用问题。
是否可以拒绝这样的不是格式的提交?
例子:
修复 gh-12 foo bar
是正确的
foo bar
会出错
更新:
差不多了,这还是不行...有什么想法吗?
我现在有以下内容:.git/hooks/commit-msg
#!/bin/bash
commit_regex='(gh-[0-9]+|merge)'
error_msg="Aborting commit. Your commit message is missing either a Github Issue ('gh-1111') or 'Merge'."
if ! grep -E "$commit_regex" <<< "$0"; then
echo "$error_msg" >&2
exit 1
fi
最佳答案
Python 版本看起来像这样:
#!/usr/bin/python
import sys
import re
ret = 1
try:
with open(sys.argv[1]) as msg:
res = re.match("^fix gh-[0-9]+.*$", msg.readline())
if res != None:
ret = 0
except:
pass
if (ret != 0):
print("error_msg_goeth_here")
sys.exit(ret)
通常它的第一行应该匹配预定义的格式,但这只是我个人的意见。
关于git - 如果提交格式不正确,是否可以拒绝 Github 上的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39764942/