提交消息中的 Git 魔术关键字(签名者、共同创作者、修复等)

2024-04-02

Git 命令本身supports https://git-scm.com/docs/git-commit the Signed-off-by: Person's name <persons@email> line.

GitHub adds https://help.github.com/en/github/committing-changes-to-your-project/creating-a-commit-with-multiple-authors Co-authored-by:行,然后在 UI 中将提交者和引用的人显示为提交作者。 (参见问题:GitHub 与私人noreply 地址共同创作 https://stackoverflow.com/questions/54076863/github-co-authored-by-with-private-noreply-address讨论如何避免暴露电子邮件地址。)

此外,GitHub https://help.github.com/en/github/managing-your-work-on-github/closing-issues-using-keywords and GitLab https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#default-closing-pattern每个都识别一组关键字来在合并提交时解决问题。

上面的 Git 魔法关键字列表完整吗?添加这些行和关键字是否有标准化流程?这些是否定义为不区分大小写?


来自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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

提交消息中的 Git 魔术关键字(签名者、共同创作者、修复等) 的相关文章

  • 如何制作 github PR 请求审查整个文件?

    有这个问题 https github com isaacs github issues 284这是相关的 允许对更改集之外的部分代码进行注释 我只是想知道是否有人有聪明的解决方法或流程来实现类似的 也许更简单的事情 因此 我有一组不同的文件
  • 第一次使用node.js - “ReferenceError:节点未定义”

    我刚刚安装了node js 我尝试编写应该检查版本的node v 但它不起作用 这是输出 gt node v ReferenceError node is not defined at repl 1 2 at REPLServer self
  • 如何合并两个连续的 git 存储库

    我有一个相当独特的情况 我有一个名为 Project1 的存储库 我在其中工作了一些时间 几个月 一年后 我创建了存储库 Project1 Again 从 Project1 停止的地方开始 现在 我希望修订历史记录是连续的 因此我希望它们合
  • git 别名中的 AWK 语句

    我正在尝试创建一个 git 别名来以特定格式打印日志中的所有拉取请求 但是 我在使用 AWK 删除双空格时遇到问题 这是使用以下命令的 git log 的输出 git log merges grep pull request pretty
  • 默认情况下 git merge -Xignore-space-change

    我该如何设置该选项ignore space change对于所有合并使用git config 我也许可以使用别名merge 但因为我希望该设置应用于git stash pop git stash apply git pull and git
  • Jenkins 和 Github 不使用 SSH 密钥

    我已将 Jenkins 设置为从 Github 上的私有存储库中提取特定作业 尽管我已经生成了私钥 公钥并将其作为部署密钥添加到 github 但 Jenkins 似乎并未使用 SSH 密钥 当我从 Jenkins 用户进行 git clo
  • 我可以直接从我的谷歌云端硬盘在线推送/拉取吗?

    有一些方法可以通过谷歌驱动器同步 Windows 应用程序将我的本地 git 存储库同步到我的谷歌驱动器 但我想知道我是否可以完全绕过它的需要 Fro eg git remote add origin https drive google
  • 使用终端时 Git 推送在总计后卡住了?

    我尝试将一些文件推送到Github 总大小只有22 2M 我不知道为什么它在总行之后卡住了 我读过推送到 Github 时 Git 推送挂起 https stackoverflow com questions 16906161 git pu
  • 如何使用脚本在 GitHub 上发布构建工件资产?

    我正在尝试找出一种在 GitHub 上生成构建的单命令流程 我预计要做的是运行某种命令 比如 make release make release 脚本会构建发布工件 然后以某种方式将其上传到 GitHub 然而 我对如何在 GitHub 上
  • Git 将一个分支合并到所有其他分支中

    我知道这个问题已经在这里被问过 https stackoverflow com questions 2329716 merging changes from master into all branches using git https
  • 当当前分支上有未提交的更改时签出另一个分支

    大多数时候 当我尝试签出另一个现有分支时 如果我在当前分支上有一些未提交的更改 Git 会不允许我这样做 所以我必须首先提交或隐藏这些更改 然而 有时 Git 确实允许我在不提交或存储这些更改的情况下签出另一个分支 并且它会将这些更改携带到
  • 如何使用 Git 跟踪目录而不是文件?

    我最近开始使用 Git 但只有一件事遇到了麻烦 如何在不跟踪目录内容的情况下跟踪目录 例如 我正在开发的网站允许上传 我想跟踪上传目录 以便在分支等时创建它 但显然不是其中的文件 在开发分支中的测试文件或主控中的真实文件 在我的 gitig
  • Git 2.2.x 无缘无故更新旧包文件的时间戳

    Git 2 2 0 和 2 2 1 似乎修改了旧的时间戳 git objects pack pack pack偶尔会无缘无故地文件 它只是改变时间戳 内容是相同的 调试这一点很困难 因为它似乎很少进行更改 我在 2 2 0 之前的任何 Gi
  • Android 存储库初始化失败

    我想我非常仔细地遵循该网站的说明 http source android com source downloading html http source android com source downloading html 但是当我尝试这
  • 如何让 Aptana Studio 记住 git ssh 密码

    我找不到任何有关如何获得 Aptana Studio 的内置 git 支持来记住执行推 拉操作的 ssh 密码的指南 信息 有人有什么想法吗 Aptana Studio 实际上是内置的 GIT 程序 它将在 Windows 上的 C Use
  • 缺少节点-v59-linux-x64/grpc_node.node

    我正在尝试在我的服务器中使用 Firebase admin SDK 当我部署时 出现错误 我在 firebase admin node module 映射中缺少文件 node v59 linux x64 grpc node node 我在包
  • 为什么 Git 无法将文件更改与修改后的父级/主控合并?

    我有一个文件 里面只有一行 我创建一个分支并向同一文件添加第二行 保存并提交到分支 我切换回主人 并向文件中添加不同的第二行 保存并提交给master 现在总共有 3 条独特的线路 如果我现在尝试将分支合并回主分支 则会遇到合并冲突 为什么
  • 使用 gitignore 嵌套存储库。

    我想嵌套 2 个 git 存储库 我一直在阅读子模块 有一段时间我认为它很棒 我想我可能想要其他东西 这是我的情况 首先 我想我应该提到我的所有服务器都托管网站 并以 staging domain com 和 domain com 实时 模
  • Eclipse Git 关键字扩展

    每次我检查 git hub 服务器的源代码时 我都需要更新源代码修订关键字 version date 等 你可能知道 Git 中的主要问题是你无法使用以下命令修改文件 提交后有关提交的信息 因为 Git 首先对文件进行校验 基本上我想要实现
  • git 是否有任何静态接口?

    我一直在寻找一个宁静的 git api 但似乎没有找到 我得到的最接近的是 Github 的 api 来访问一些存储库信息 还有其他的实施吗 Orion Git API http wiki eclipse org Orion Server

随机推荐