Git-检测提交是否被注销 [英] Git - Detect if commit is signed off

查看:108
本文介绍了Git-检测提交是否被注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何git命令或更简单的格式来确定提交是否已注销?

Is there any git command or easier format to determine if a commit is or isn't signed off?

推荐答案

使用 Git 1.7.9 ,2011年10月,您如何git log --show-signature(在 Kris 中提到带有2.10(2016年第三季度),只需设置git config log.showSignature true,即可与git-loggit-showgit-whatchangedgit-reflog一起使用.

With Git 1.7.9, Oct. 2011, you how git log --show-signature (mentioned in Kris' answer), but with 2.10 (Q3 2016), you can simply set git config log.showSignature true, which will work with git-log, git-show, git-whatchanged and git-reflog.

为了便于grepping"Signed-off-By",您现在(Git 2.12,2017年第一季度)只能使用"trailer"登录.提交消息的一部分. (预告片包括"Signed-off-By"和其他"Acknowledged By"消息)

To facilitate grepping "Signed-off-By", you now (Git 2.12, Q1 2017) can log with only the "trailer" part of the commit message. (The trailer includes the "Signed-off-By" and other "Acknowledged By" messages)

请参见提交b1d31c8 Junio C Hamano-gitster-

See commit b1d31c8, commit d9f31fb (19 Nov 2016) by Jacob Keller (jacob-keller). (Merged by Junio C Hamano -- gitster -- in commit f008159, 19 Dec 2016, Git 2.12.0-rc0)

pretty:添加%(trailers)格式以显示提交消息的预告片

pretty: add %(trailers) format for displaying trailers of a commit message

除了%(subject)%(body),"git log --pretty=format:..."外, 学习了新的占位符%(trailers)%(contents:trailers).

In addition to %(subject), %(body), "git log --pretty=format:..." learned a new placeholder %(trailers) and %(contents:trailers).

您还具有 git interpret-trailers ,它在Git 2.14.x/2.15(2017年第三季度)中得到了发展

You also have git interpret-trailers, which has just evolved in Git 2.14.x/2.15 (Q3 2017)

请参见提交5a0d0c0 (2017年8月20日),由.
参见
提交58311c6 提交99e09da 提交fdbdb64 提交56c493e (2017年8月15日) ,和 Jeff King(peff) .
(由 Junio C Hamano-gitster-

See commit 5a0d0c0 (20 Aug 2017) by Martin Ågren (``).
See commit 58311c6, commit cc1735c, commit a388b10, commit 99e09da, commit 0000239, commit fdbdb64, commit 56c493e (15 Aug 2017), and commit 8abc898 (10 Aug 2017) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 06cf4f2, 27 Aug 2017)

" git interpret-trailers"已被教导""还有一些 其他选项,以使脚本更容易获取现有内容 提交日志消息中的结尾行.

"git interpret-trailers" has been taught a "--parse" and a few other options to make it easier for scripts to grab existing trailer lines from a commit log message.

git log --pretty=format:%(trailers:only:unfold)

实际上:

git log --pretty=format:%(trailers:only,unfold)
                                     ^^^^^

请参见提交84ff053 (2017年10月1日),由 Junio C Hamano-gitster-

See commit 84ff053 (01 Oct 2017) by Taylor Blau (ttaylorr).
(Merged by Junio C Hamano -- gitster -- in commit 436b359, 07 Oct 2017)

pretty.c:分隔"%(trailers)",带","

的参数

pretty.c: delimit "%(trailers)" arguments with ","

准备添加一致的"%(trailers)".原子选项 git-for-each-ref(1)的"--format"参数,更改"%(trailers)"在 pretty.c可以用","而不是":"来分隔子参数.

In preparation for adding consistent "%(trailers)" atom options to git-for-each-ref(1)'s "--format" argument, change "%(trailers)" in pretty.c to separate sub-arguments with a ",", instead of a ":".

多个子参数以"%(trailers:unfold,only)"的形式给出.或者 "%(trailers:only,unfold)".

Multiple sub-arguments are given either as "%(trailers:unfold,only)" or "%(trailers:only,unfold)".

此更改可消除顶级"和顶级"之间的歧义.论点和论点 给拖车原子本身.这与行为一致 "%(upstream)"和"%(push)"原子.

This change disambiguates between "top-level" arguments, and arguments given to the trailers atom itself. It is consistent with the behavior of "%(upstream)" and "%(push)" atoms.


注意:使用Git 2.20(2018年第四季度)时,此功能更加强大,因为"git interpret-trailers"它的底层机制有一个错误的代码,试图在提交日志消息后忽略补丁文本,这会触发各种代码路径,这些代码路径将始终仅获取日志消息,而永远不会得到这样的输入.


Note: this is more robust with Git 2.20 (Q4 2018), since "git interpret-trailers" and its underlying machinery had a buggy code that attempted to ignore patch text after commit log message, which triggered in various codepaths that will always get the log message alone and never get such an input.

请参见提交66e83d9 提交e5fba5d 提交1688c9a 提交00a21f5 提交a3b636e Jeff King(peff) .
(由 Junio C Hamano-gitster-

See commit 66e83d9, commit ffce7f5, commit e5fba5d, commit 1688c9a, commit c188668, commit 00a21f5, commit a3b636e, commit 0d2db00 (23 Aug 2018) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit fba9654, 17 Sep 2018)

sequencer:忽略"---"解析预告片时的分隔符

sequencer: ignore "---" divider when parsing trailers

当定序器代码附加签收或原始选择时,它将使用默认的预告片解析选项,该选项将"---"视为"---".作为提交消息的结尾.
结果,它可能会被包含该字符串的提交消息所欺骗,而无法找到现有的预告片.更令人困惑的是,实际的附加代码不了解"---",而是始终附加到字符串的末尾.
这可能会导致奇怪的结果.

When the sequencer code appends a signoff or cherry-pick origin, it uses the default trailer-parsing options, which treat "---" as the end of the commit message.
As a result, it may be fooled by a commit message that contains that string and fail to find the existing trailer block. Even more confusing, the actual append code does not know about "---", and always appends to the end of the string.
This can lead to bizarre results.

例如,将签名添加到提交消息中,如下所示:

E.g., appending a signoff to a commit message like this:

 subject

 body
 ---
 these dashes confuse the parser!

 Signed-off-by: A

输出结果的最后一个块如下:

results in output with a final block like:

 Signed-off-by: A

 Signed-off-by: A

解析器认为消息的最后一行是正文",并忽略其他所有内容,声称没有预告片.
因此,我们输出了一个额外的换行分隔符(错误)并添加了重复的签核(也是错误的).

The parser thinks the final line of the message is "body", and ignores everything else, claiming there are no trailers.
So we output an extra newline separator (wrong) and add a duplicate signoff (also wrong).

由于我们知道我们正在馈入纯提交消息,因此我们可以简单地告诉解析器忽略"---"消息.分隔线.


Git 2.22(Q2 2019)添加了几个选项:


Git 2.22 (Q2 2019) adds several options:

请参见提交0b691d8 提交d9b936d 提交250bea0 提交4261775 (2018年12月8日),由 Junio C Hamano-gitster-

See commit 0b691d8, commit fd2015b, commit d9b936d, commit 250bea0, commit 3e3f347 (28 Jan 2019), commit 4f732e0 (29 Jan 2019), and commit 4261775 (08 Dec 2018) by Anders Waldenborg (wanders).
(Merged by Junio C Hamano -- gitster -- in commit 42977bf, 07 Mar 2019)

pretty:在%(trailers)

中添加对separator选项的支持

默认情况下,预告片行以换行符('\n')终止.
通过指定新的'separator'选项,它们将改为由 用户提供的字符串并具有分隔符而不是终止符 语义.
分隔符字符串可以包含文字格式代码%n%xNN,从而使它们成为难以键入的内容,例如%x00或逗号和结尾括号,它们会破坏解析.

By default trailer lines are terminated by linebreaks ('\n').
By specifying the new 'separator' option they will instead be separated by user provided string and have separator semantics rather than terminator semantics.
The separator string can contain the literal formatting codes %n and %xNN allowing it to be things that are otherwise hard to type such as %x00, or comma and end-parenthesis which would break parsing.

例如:

$ git log --pretty='%(trailers:key=Reviewed-by,valueonly,separator=%x00)'

并且:

pretty:添加对"valueonly"的支持; %(trailers)

中的选项

pretty: add support for "valueonly" option in %(trailers)

使用新的"key=" %(trailers)的选项通常对 显示密钥,因为根据定义它已经知道哪个预告片是 在那里印刷.
此新的"valueonly"选项使其在打印预告片时省略键.

With the new "key=" option to %(trailers) it often makes little sense to show the key, as it by definition already is knows which trailer is printed there.
This new "valueonly" option makes it omit the key when printing trailers.

例如:

$ git show -s --pretty='%s%n%(trailers:key=Signed-off-by,valueonly)' aaaa881

will show:

> upload-pack: fix broken if/else chain in config callback
> Jeff King <peff@peff.net>
> Junio C Hamano <gitster@pobox.com>


"的解析器git for-each-ref --format=... (%(trailers...)"时,它太松散了.原子,并忘记了"trailers"和"trailers:<modifiers>"是仅有的两种允许的形式,已通过Git 2.29(2020年第四季度)更正.


The parser for "git for-each-ref --format=...(man)" was too loose when parsing the "%(trailers...)" atom, and forgot that "trailers" and "trailers:<modifiers>" are the only two allowed forms, which has been corrected with Git 2.29 (Q4 2020).

请参见提交2c22e10 Junio C Hamano-gitster-

See commit 2c22e10, commit a8e0f50 (21 Aug 2020) by Hariom Verma (harry-hov).
(Merged by Junio C Hamano -- gitster -- in commit e177238, 31 Aug 2020)

ref-filter :如果:,则'contents:trailers'显示错误丢失了

指导者:克里斯蒂安·库德(Christian Couder)
指导者:Heba Waly
帮助人:埃里克·阳光(Eric Sunshine)
签名人:Hariom Verma

ref-filter: 'contents:trailers' show error if : is missing

Mentored-by: Christian Couder
Mentored-by: Heba Waly
Helped-by: Eric Sunshine
Signed-off-by: Hariom Verma

如果与'trailers'原子一起使用,则'contents'原子不会显示任何错误,并且在预告片参数之前缺少冒号.

The 'contents' atom does not show any error if used with 'trailers' atom and colon is missing before trailers arguments.

例如%(contents:trailersonly)可以工作,但不可以.

e.g %(contents:trailersonly) works, while it shouldn't.

这绝对不是预期的行为.

It is definitely not an expected behavior.

让我们修复此错误.

这篇关于Git-检测提交是否被注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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