是否可以修改默认git提交消息的注释部分?我想为我的用户添加更多“上下文”信息。
# Please enter the commit message for your changes.
# (Comment lines starting with '#' will not be included)
# Explicit paths specified without -i nor -o; assuming --only paths...
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test.txt
#
你可以使用git hooks。在提交更改的人员显示提交消息之前,将运行prepare-commit-msg脚本。
您可以在.git / hooks中找到一个示例prepare-commit-msg脚本。
要编辑默认消息,请在.git / hooks文件夹中创建名为prepare-commit-msg的新文件。您可以使用如下脚本编辑提交消息:
#!/bin/sh
echo "#Some more info...." >> $1
$ 1变量存储提交消息文件的文件路径。
有commit.template
配置变量,根据git-config(1)手册页:
指定要用作新提交消息模板的文件。 “
~/
”扩展为$ HOME和“~user/
”的值到指定用户的主目录。
您可以将它放在per-repository(.git/config
),用户(~/.gitconfig
)和system(/etc/gitconfig
)配置文件中。
这是一个python git-hook来清理默认消息。钩名:prepare-commit-msg
。
#!/usr/bin/env python
import sys
commit_msg_file_path = sys.argv[1]
with open(commit_msg_file_path, 'a') as file:
file.write('')
您只需在file.write()
方法中添加文本即可。