我正在开发 GitLab 的私人安装,我想知道是否有一种方法可以在回答问题时在评论末尾自动附加一串文本(例如签名)。
预先感谢您提供的任何帮助。
Gitlab 中没有任何东西可以让您自动修改提交消息,或者在 Git 中附加到消息(据我所知),但您可以使用 Git Hook 在提交消息前面添加文本。这对于将分支名称或用户故事 ID 添加到提交消息非常有用。
Git Hooks 在项目的
.git/hooks
目录中定义。 hooks
目录有一些示例文件,向您展示不同的挂钩如何工作。文件 prepare-commit-msg.sample
中的示例展示了与提交消息交互的多种方法,其中一种是将“由 John Doe 签署”行添加到提交消息中的方法,这与您所使用的类似要求:
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
# This hook includes three examples. The first one removes the
# "# Please enter the commit message..." help message.
#
# The second includes the output of "git diff --name-status -r"
# into the message, just before the "git status" output. It is
# commented because it doesn't cope with --amend or with squashed
# commits.
#
# The third example adds a Signed-off-by line to the message, that can
# still be edited. This is rarely a good idea.
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
# case "$COMMIT_SOURCE,$SHA1" in
# ,|template,)
# /usr/bin/perl -i.bak -pe '
# print "\n" . `git diff --cached --name-status -r`
# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
# *) ;;
# esac
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
# if test -z "$COMMIT_SOURCE"
# then
# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
# fi
如果取消最后一位注释,git 将使用
GIT_COMMITTER_IDENT
将 Signed-off-by Committer
变量的值添加到提交消息中。
注意:它说在示例中修改提交消息是一个坏主意,但我不确定为什么。我编辑了您的问题以添加
git
标签,所以希望其他人会比我更了解它。
正如我在我对描述
git
-本地提交消息的答案的评论中提到的那样,您似乎在询问GitLab问题/PR/提交评论而不是git
-本机提交消息。 目前这似乎不可能。但是,我已在
https://gitlab.com/gitlab-org/gitlab/-/issues/458465 提交了功能请求。