来自OP:
The git
命令本身支持Signed-off-by: Person's name <persons@email>
line.
从 Git 2.32(2021 年第 2 季度)开始,git
命令本身支持...任何您想要的预告片!
"git commit https://github.com/git/git/blob/68e15e0c231bfa50e254fc87d054649161a7e301/Documentation/git-commit.txt"(man https://git-scm.com/docs/git-commit) learned --trailer <key>[=<value>]
option; together with the interpret-trailers command, this will make it easier to support custom trailers.
See commit 2daae3d https://github.com/git/git/commit/2daae3d1d1bf513f1e1c00f1e4df75e1cb500e0f (23 Mar 2021) by ZheNing Hu (adlternative) https://github.com/adlternative.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 68e15e0 https://github.com/git/git/commit/68e15e0c231bfa50e254fc87d054649161a7e301, 07 Apr 2021)
commit https://github.com/git/git/commit/2daae3d1d1bf513f1e1c00f1e4df75e1cb500e0f: 添加 --trailer 选项
Signed-off-by: ZheNing Hu
从历史上看,Git 一直支持 'Signed-off-by
' 使用 ' 提交预告片--signoff
' 和 '-s
' 命令行选项。
但用户可能需要从命令行提供其他预告片信息,例如“Helped-by
", "Reported-by
", "Mentored-by
",
现在实施一个新的--trailer <token>[(=|:)<value>]
将其他拖车传递到的选项interpret-trailers
并将它们插入提交消息中。
git commit
现在包含在其man page https://github.com/git/git/blob/2daae3d1d1bf513f1e1c00f1e4df75e1cb500e0f/Documentation/git-commit.txt#L170-L180:
--trailer <token>[(=|:)<value>]
指定一个 (<token>
, <value>
)应作为一个应用的对
预告片。
例如:
git commit --trailer "Signed-off-by:C O Mitter <[email protected] /cdn-cgi/l/email-protection>" \
--trailer "Helped-by:C O Mitter <[email protected] /cdn-cgi/l/email-protection>"
这将添加“Signed-off-by
“ 预告片and the "Helped-by
" 提交消息的预告片。
The trailer.*
配置变量
(git interpret-trailers https://git-scm.com/docs/git-interpret-trailers) 可用于定义 if
省略了重复的预告片,其中在预告片的运行中
每个预告片都会出现,以及其他细节。
关于那件事trailer.xxx
配置,考虑您想要修改的初始提交额外的拖车:
Signed-off-by: C O Mitter <[email protected] /cdn-cgi/l/email-protection>
Signed-off-by: C1 E1
Reported-by: C3 E3
Mentored-by: C4 E4
Helped-by: C3 E3
A trailer.ifexists="replace"
config 会,如果您通过添加来修改它same举报者,保持消息不变:
git -c trailer.ifexists="replace" \
commit --trailer "Mentored-by: C4 E4" \
--trailer "Helped-by: C3 E3" \
--amend
但是如果你修改同一个提交trailer.ifexists="add"
意思是:
Signed-off-by: C O Mitter <[email protected] /cdn-cgi/l/email-protection>
Signed-off-by: C1 E1
Helped-by: C2 E2
Reported-by: C3 E3
Mentored-by: C4 E4
Reported-by: C3 E3 <<<< added twice
Mentored-by: C4 E4 <<<< added twice
并使用trailer.ifexists="addIfDifferent"
git -c trailer.ifexists="addIfDifferent" \
commit --trailer "Reported-by: C3 E3" \
--trailer "Mentored-by: C5 E5" \
--amend
你得到:
Signed-off-by: C O Mitter <[email protected] /cdn-cgi/l/email-protection>
Signed-off-by: C1 E1
Helped-by: C2 E2
Reported-by: C3 E3
Mentored-by: C4 E4
Mentored-by: C5 E5 <<<< Only C5 E5 is added
而且,在 Git 2.32(2021 年第 2 季度)中,命令行指定的方式仍然是trailer.<token>.command
配置变量接收最终用户提供的值既容易出错又具有误导性。
添加了一种以更安全、更直观的方式实现相同目标的替代方案,因为trailer.<token>.cmd
配置变量,替换它。
See commit c364b7e https://github.com/git/git/commit/c364b7ef51ec3af871754e7afdfd73e4bed6da56, commit 57dcb65 https://github.com/git/git/commit/57dcb6575b577a70f02814df4291e8af6ed81f86 (03 May 2021) by ZheNing Hu (adlternative) https://github.com/adlternative.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 2cd6ce2 https://github.com/git/git/commit/2cd6ce21f38b9dab1b3a75f05b24e92bdc4b5b93, 11 May 2021)
trailer https://github.com/git/git/commit/c364b7ef51ec3af871754e7afdfd73e4bed6da56:添加新的.cmd配置选项
Helped-by: Junio C Hamano
Helped-by: Christian Couder
Signed-off-by: ZheNing Hu
The trailer.<token>.command
配置变量指定一个命令(通过 shell 运行,因此它不必是命令的单个名称或路径,但可以是 shell 脚本),以及子字符串的第一次出现$ARG
被替换为给定的值interpret-trailer
' 中令牌的命令--trailer <token>=<value>
' 争论。
这有三个缺点:
- 指某东西的用途
$ARG
该机制误导用户
该值被传递到 shell 变量中,并诱惑他们使用$ARG
不止一次,但这行不通,因为第二次和后续$ARG
没有被替换。
- Because
$ARG
被文本替换而不考虑
shell 语言语法,甚至 '$ARG
' (在单引号对内),用户希望保持完整,将被替换,并且更糟糕的是,如果该值具有不匹配的单引号(想象像“O'Connor”这样的名称,替换为NAME='$ARG'
做到这一点NAME='O'Connor'
),这会导致语法不正确(或更糟)的损坏命令。
- 子串第一次出现
$ARG
将被替换为空字符串,在命令中首次调用时添加指定的预告片<token>
.
这是一个糟糕的设计,自动执行的本质导致它添加了我们不期望的预告片。
Introduce a new trailer.<token>.cmd
configuration that takes higher precedence to deprecate and eventually remove trailer.<token>.command
, which passes the value as an argument to the command.
Instead of "$ARG
", users can refer to the value as positional argument, $1, in their scripts.
At the same time, in order to allow git interpret-trailers https://github.com/git/git/blob/c364b7ef51ec3af871754e7afdfd73e4bed6da56/Documentation/git-interpret-trailers.txt(man https://git-scm.com/docs/git-interpret-trailers) to better simulate the behavior of git command -s
, 'trailer.<token>.cmd
' will not automatically execute.
git interpret-trailers
现在包含在其man page https://github.com/git/git/blob/c364b7ef51ec3af871754e7afdfd73e4bed6da56/Documentation/git-interpret-trailers.txt#L235-L248:
此选项的行为方式与 'trailer.<token>.cmd
', 除了
它不会将任何内容作为参数传递给指定的命令。
相反,子字符串第一次出现$ARG
被替换为
将作为参数传递的值。
The 'trailer.<token>.command
' 选项已被弃用,取而代之的是
'trailer.<token>.cmd
' 由于这个事实$ARG
在用户的命令中是
只更换一次,而且还是原来的更换方式$ARG
不安全。
当两个 'trailer.<token>.cmd
' and 'trailer.<token>.command
' 给出
对于相同的<token>
, 'trailer.<token>.cmd
' 被使用并且
'trailer.<token>.command
' 被忽略。
trailer.<token>.cmd
git interpret-trailers
现在包含在其man page https://github.com/git/git/blob/c364b7ef51ec3af871754e7afdfd73e4bed6da56/Documentation/git-interpret-trailers.txt#L264-L266:
这些参数中的一个(如果有)将作为其参数传递给命令
第一个论点。
这样该命令就可以产生一个计算结果
来自<value>
通过在 '--trailer <token>=<value>
' 争论。
git interpret-trailers
现在包含在其man page https://github.com/git/git/blob/c364b7ef51ec3af871754e7afdfd73e4bed6da56/Documentation/git-interpret-trailers.txt#L349-L397:
- 使用 cmd 使用脚本配置“帮助”预告片
glog-find-author
从 git 存储库中的 git log 中搜索指定的作者身份
并展示它是如何工作的:
$ cat ~/bin/glog-find-author
#!/bin/sh
test -n "$1" && git log --author="$1" --pretty="%an <%ae>" -1 || true
$ git config trailer.help.key "Helped-by: "
$ git config trailer.help.ifExists "addIfDifferentNeighbor"
$ git config trailer.help.cmd "~/bin/glog-find-author"
$ git interpret-trailers --trailer="help:Junio" --trailer="help:Couder" <<EOF
> subject
>
> message
>
> EOF
subject
message
Helped-by: Junio C Hamano <[email protected] /cdn-cgi/l/email-protection>
Helped-by: Christian Couder <[email protected] /cdn-cgi/l/email-protection>
- 使用 cmd 使用脚本配置“ref”预告片
glog-grep
从 git 存储库中的 git log 中 grep 最后一个相关提交
并展示它是如何工作的:
$ cat ~/bin/glog-grep
#!/bin/sh
test -n "$1" && git log --grep "$1" --pretty=reference -1 || true
$ git config trailer.ref.key "Reference-to: "
$ git config trailer.ref.ifExists "replace"
$ git config trailer.ref.cmd "~/bin/glog-grep"
$ git interpret-trailers --trailer="ref:Add copyright notices." <<EOF
> subject
>
> message
>
> EOF
subject
message
Reference-to: 8bc9a0c769 (Add copyright notices., 2005-04-07)