提交消息中的 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 魔术关键字(签名者、共同创作者、修复等) 的相关文章

  • 合并之间的 git rebase 会导致完全不相关的文件发生冲突

    我有一个大型 Git 存储库 几个月前引入了一个错误 我想bisect它 首先引入一个过去的提交 存储库 然后重播合并 做rebase到新的 commit 如下图所示 据我了解 由于合并 Git 似乎无法正常工作 预期的 但我想更好地了解为
  • 如何在本地快速拉取拉取请求

    在合并拉取请求之前 我想在本地快速拉取请求并运行测试并测试一些内容 我还不想点击 gihub 合并拉取请求 我以为滑轮会有帮助http ejohn org blog pulley http ejohn org blog pulley 但我收
  • Git 在推送代码时返回错误 403 [重复]

    这个问题在这里已经有答案了 一切都工作正常 直到我创建了一个新的 GitHub 帐户 当我尝试使用新帐户第一次将代码推送到 github 服务器时 出现以下错误 remote Permission to NEW USER NEW REPO
  • 如何使用 sourceTree 进行推送?

    我正在使用 sourceTree 管理 Unity 项目 版本 4 6 3 我只是想返回到上一次提交 右键选择 将当前分支重置到此提交 在使用模式中选择 硬 然后放回上一次提交 之后 我尝试去推 但没有成功 抱歉 当时我忘记了错误 之后 我
  • 如何通过哈希显示提交的日期和时间

    I used git reflog识别我创建特定分支时的哈希值 我得到了哈希值fe1ddcdef 我还没有将此分支推送到远程 我现在正在尝试查找日期和时间fe1ddcdef发生 git reflog只告诉我 fe1ddcdef HEAD 1
  • 无法从我的电脑上使用 traefik 后面的 gitlab 进行 git 克隆

    这是我的 gitlab 和 traefik 配置 version 3 7 services gitlab web image gitlab gitlab ce latest restart always hostname gitlab ro
  • 从 github 中删除子项目提交

    我有两个存储库A and B 我错误地在我的机器上将仓库 B 克隆到了 A 内 我从存储库 B 中删除了所有代码 但是当我在源上从 A 推送并合并代码时 它还显示了子项目提交B在 Github 仓库上 我想从我的 master 上删除子项目
  • 是否可以在 git 存储库之外添加和提交文件?

    我们的文本文件分布在系统的各个角落 我们计划将这些文件中所做的所有修改添加到 git 存储库中 每次对这些文件进行修改都是由脚本进行的 因此 我们计划向该脚本添加新命令 以将文件添加到 git 存储库 但是 这些修改是同时进行的 我们可以为
  • 自动生成/删除詹金斯工作

    我正在寻找一种自动创建一组詹金斯作业的方法 通常在创建新的 git 分支之后 我已经为maven尝试过这个插件 http evgeny goldin com wiki Maven jenkins plugin http evgeny gol
  • 致命:不是 git 存储库(或任何父目录):.git [重复]

    这个问题在这里已经有答案了 当我尝试推送 github com 上的现有存储库时 当我输入命令时 网站提示我将其输入终端 我收到了以下致命错误消息 Not a git repository or any of the parent dire
  • git Blame:合并后正确的作者

    GIT 合并引入了新的提交 这会导致 git Blame 问题 合并的行似乎是由进行合并的开发人员提交的 我可以理解这种情况冲突的变化 因为他解决了冲突 但是有没有办法让非冲突线路不发生这种情况呢 一些 git Blame 的选择 如果没有
  • 无法使用 git 推送或获取 [重复]

    这个问题在这里已经有答案了 我可以拉 但无法使用 git 版本 1 9 5 推送或获取 它突然开始给我以下错误 关于如何修复它有什么想法吗 git fetch fatal unable to access https email prote
  • 如何禁用 GitHub 中的拉取请求?

    我试图了解如何禁用 github 中的 拉取请求 问题一 我们正在尝试使用变基工作流程 这意味着如果不是快速推进 那么使用拉取请求可能会有害 一种解决方案 为我想要禁用拉取请求的分支设置分支权限 或者将我添加为任何进入 master 的内容
  • 从分叉存储库的 GitHub 操作发布评论的解决方法

    我需要在 GitHub 操作完成后向 GitHub 拉取请求发表评论 例如当 FOSS 社区成员提交 PR 时 我知道 当操作从分叉的存储库运行时 令牌没有对父存储库的写访问权限 因此它无法发布评论 人们是否为此找到了任何可行的解决方法 我
  • 将“复制到剪贴板”添加到 GitHub markdown 的简单方法?

    具体来说 我有一些用于安装的代码块 我希望用户能够快速将其复制并粘贴到终端中 我想要一个用于代码块 复制到剪贴板 的按钮 由于 git 克隆 URL 有一个 复制到剪贴板 按钮 我想知道我是否可以利用该按钮 或者如果不能 是否可以将一些相对
  • 如何撤消删除 github wiki 页面的操作?

    我删除了 github 存储库 wiki 上的一个页面 单击该文件的链接现在会将我带到一个新的编辑屏幕 我认为这可能是在我的存储库分支中 但是在 chrome 上以隐身模式点击链接会出现错误 表明我无权编辑此文件 大概是因为我正在尝试创建它
  • 如何关闭分支而不将其从 git 的历史记录中删除?

    我想提交并关闭其分支 而不将其从历史中删除 有了水银我会commit close branch then update转到上一个 然后继续工作 有了 git 我很困惑 没有与 Git 中关闭分支完全相同的方法 因为 Git 分支比 Merc
  • 我可以忽略全局 .gitignore 吗?

    我的全局 gitignore 一般都很棒 但对于这个一次性项目 我不希望应用全局规则 如何删除这个怪异存储库的全局 gitignore 规则 在您的存储库中运行此命令 git config local core excludesfile f
  • 为什么 git-svn 应该积极搜索旧历史?

    当我运行 git svn clone s 时发生了一些奇怪的事情 尽管以下信息告诉我们不要惊慌 但我想知道为什么会出现这种 svn 错误 为什么这个路径不存在 是被别人删除了吗 如果是 为什么 git svn 应该积极搜索旧历史记录 Ini
  • SSL 适用于浏览器、wget 和curl,但不适用于 git

    我有一个网站 用于托管 redmine 和几个 git 存储库 这非常适合 http 但我无法使用 https 进行克隆 即 git clone http mysite com git test git 工作正常 但是 git clone

随机推荐