如何更改 git 提交消息中的默认注释?
是否可以修改默认 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
#
Is it possible to modify the commented part of the default git commit message?
I want to add a bit more 'context' information for my users.
# 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
#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有
commit.template
配置变量,根据 git-config(1) 联机帮助页:您可以将其放入每个存储库 (
.git/config
)、用户的 (~/.gitconfig
) 和系统 (/etc/gitconfig
) )配置文件。There is
commit.template
configuration variable, which according to git-config(1) manpage:You can put it in per-repository (
.git/config
), user's (~/.gitconfig
) and system (/etc/gitconfig
) configuration file(s).您可以使用 git hooks 来实现这一点。在向想要提交更改的人显示提交消息之前,将运行prepare-commit-msg 脚本。
您可以在.git/hooks 中找到一个示例prepare-commit-msg 脚本。
要编辑默认消息,请在 .git/hooks 文件夹中创建一个名为prepare-commit-msg 的新文件。您可以使用如下脚本编辑提交消息:
$1 变量存储提交消息文件的文件路径。
You can use git hooks for that. Before the person who wants to commit the changes is shown the commit message, the prepare-commit-msg script is run.
You can find an example prepare-commit-msg script in .git/hooks.
To edit the default message create a new file called prepare-commit-msg in the .git/hooks folder. You can edit the commit message by using a script like this:
The $1 variable stores the file path to the commit message file.
这是一个python git-hook来清理默认消息。挂钩名称:
prepare-commit-msg
。您只需在
file.write()
方法中添加文本即可。Here is a python git-hook to clean up the default message. Hook name:
prepare-commit-msg
.You can simply add you text in the
file.write()
method.将类似的内容放入
.gitconfig
(源):并在该文件内容中设置默认提交消息。
Put something like this in
.gitconfig
(source):and in that file content, set your default commit message.