是否可以在 Git 中签署合并提交?

Is it possible to sign-off a Merge Commit in Git?

我必须签署我的每一次提交才能推送到原点。但是,合并提交未签署,我使用 sourcetree 和 git 控制台,无法签署合并提交。有什么办法可以做到吗?

合并完成后可以运行git commit --amend --no-edit -s

一种方法是合并,然后 "git commit --amend" 提交以更改提交消息,或者与“--no-commit”合并,然后使用 signed-off-by 行手动提交。

合并通常不会引入新的更改,因此并不总是需要签名。

您可以在不提交的情况下进行合并:

git merge --no-commit

Git 一切准备就绪。之后你完成与

的合并
git commit -s

如果幸运的话,--signoff 将作为参数添加到 git 合并中。似乎有工作正在进行,请参阅本月早些时候的 this patch

到那时,其他答案就可以了。但是,我想建议为简单起见添加一个别名。例如,将以下内容添加到您的 .git/config 文件中。

[alias]
    merge-signed = !git merge --no-commit  && git commit -is

然后:

git merge-signed feature

是的,Git 2.14.x/2.15(2017 年第 3 季度)

参见 commit 14d01b4 (04 Jul 2017) by Łukasz Gryglicki (lukaszgryglicki)
(由 Junio C Hamano -- gitster -- in commit bdfc15f 合并,2017 年 8 月 24 日)

merge: add a --signoff flag

Some projects require every commit, even merges, to be signed off.

Because "git merge" does not have a "--signoff" option like "git commit" does, the user needs to add one manually when the command presents an editor to describe the merge, or later use "git commit --amend --signoff".

Help developers of these projects by teaching "--signoff" option to "git merge".