如何更改 git 提交消息中的默认注释?

发布于 2024-09-28 13:19:42 字数 389 浏览 6 评论 0原文

是否可以修改默认 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

国际总奸 2024-10-05 13:19:42

commit.template 配置变量,根据 git-config(1) 联机帮助页:

指定一个文件用作新提交消息的模板。 “~/”扩展为 $HOME 的值,“~user/”扩展为指定用户的主目录。

您可以将其放入每个存储库 (.git/config)、用户的 (~/.gitconfig) 和系统 (/etc/gitconfig) )配置文件。

There is commit.template configuration variable, which according to git-config(1) manpage:

Specify a file to use as the template for new commit messages. "~/" is expanded to the value of $HOME and "~user/" to the specified user's home directory.

You can put it in per-repository (.git/config), user's (~/.gitconfig) and system (/etc/gitconfig) configuration file(s).

在梵高的星空下 2024-10-05 13:19:42

您可以使用 git hooks 来实现这一点。在向想要提交更改的人显示提交消息之前,将运行prepare-commit-msg 脚本。

您可以在.git/hooks 中找到一个示例prepare-commit-msg 脚本。

要编辑默认消息,请在 .git/hooks 文件夹中创建一个名为prepare-commit-msg 的新文件。您可以使用如下脚本编辑提交消息:

#!/bin/sh
echo "#Some more info...." >> $1

$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:

#!/bin/sh
echo "#Some more info...." >> $1

The $1 variable stores the file path to the commit message file.

眸中客 2024-10-05 13:19:42

这是一个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() 方法中添加文本即可。

Here is a python git-hook to clean up the default message. Hook name: 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('')

You can simply add you text in the file.write() method.

方觉久 2024-10-05 13:19:42

将类似的内容放入 .gitconfig ():

[commit]
  template = ~/myGitMessage.txt

并在该文件内容中设置默认提交消息。

Put something like this in .gitconfig (source):

[commit]
  template = ~/myGitMessage.txt

and in that file content, set your default commit message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文