我如何更改git commit消息中的默认注释? [英] How can I change the default comments in the git commit message?

查看:298
本文介绍了我如何更改git commit消息中的默认注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以修改默认git commit消息的注释部分?
我想为我的用户添加更多'上下文'信息。

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
#


推荐答案

您可以使用 git hooks 为此。在想要提交更改的人员显示提交消息之前,运行prepare-commit-msg脚本。

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.

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

You can find an example prepare-commit-msg script in .git/hooks.

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

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

$ 1变量将文件路径存储到提交消息文件中。

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

这篇关于我如何更改git commit消息中的默认注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆