git在提交时如果需要以指定的格式提交,可以给git配置一个提交模板,配置好后,每次git commit时都会将模板中的信息作为初始化信息自动填充到编辑器的提交信息中。
以命令的方式配置:
git config --global commit.template ~/.git-commit-template
在Git配置文件中配置: 在git配置文件的commit下添加一项template即可,Git配置文件通常在 C:\Users\Administrator\.gitconfig
。其实以命令的方式执行后,它会自动在配置文件中生成这一项,Git commit的时候会去配置文件中读取这一项指定的文件中的内容,并把该内容作为初始化信息填写到提交信息中。
[commit]
template = C:/Users/arvin.chen/.git-commit-template
注意: 这里的模板文件路径是以斜杠的方式作为路径分隔符,即便是在Windows上,也是斜杠。而且文件本身只要是文本文件即可,不一定必须是txt文件,该文件也并没有规定必须放在什么位置,只需要将你实际的模板文件路径填写进去即可。
示例: 我在.gitconfig同级
目录下创建一个文本文件.git-commit-template,文本内容为:
<type>(scope): subject
1.<why>
2.<how>
<ticket>:
#example:
#
#<feat>(ehternet):Display screen turn black while vibration test.
#
#1.<why> The serializer max9291 is disturbanced by noise generated on cable.
#2.<how> disable forward/reverse control channel to deserializer
#
#<ticket>:JINKANGX1-681
# head: <type>(<scope>): <subject>
# - type: feat, fix, docs, style, refactor, test, chore
# - scope: can be any of camera/display/ota/ethernet/usb/secure/system,and etc.
# - 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?
#
# ticket:
# - refer to jira ticket, if any.
#
git仓库内容并提交git commit,编辑器中显示如下内容:
git log显示内容与提交模版一致。