使用 GPG 签署 git 提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10077996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:44:49  来源:igfitidea点击:

Sign git commits with GPG

gitgnupgpgpgit-sign

提问by austin1howard

Is there a way to sign git commits with gpg? It's so easy with tags (using -sinstead of -a), it seems there would be a similar function for commits.

有没有办法用 gpg 签署 git 提交?使用标签(使用-s而不是-a)非常容易,似乎提交会有类似的功能。

采纳答案by wRAR

git commit -S(requires git >= 1.7.9).

git commit -S(需要 git >= 1.7.9)。

回答by VonC

Note: Adding the -Soption all the time can be cumbersome.
In git 2.0 and later, you can add a config which will take care of that option for you.

注意:一直添加-S选项可能很麻烦。
在 git 2.0 及更高版本中,您可以添加一个配置来为您处理该选项。

See commit 2af2ef3by Nicolas Vigier (boklm):

提交2af2ef3尼古拉斯·Vigier(boklm)

Add the commit.gpgsignoption to sign all commits

添加对commit.gpgsign所有提交进行签名的选项

If you want to GPG sign all your commits, you have to add the -Soption all the time.
The commit.gpgsignconfig option allows to sign all commits automatically.

如果您想 GPG 签署您的所有提交,则必须-S始终添加该选项。
commit.gpgsign配置选项允许自动登录所有的提交。

commit.gpgsign

A boolean to specify whether all commits should be GPG signed.
Use of this option when doing operations such as rebase can result in a large number of commits being signed. It may be convenient to use an agent to avoid typing your GPG passphrase several times.

一个布尔值,用于指定是否所有提交都应该是 GPG 签名的。
在执行诸如 rebase 之类的操作时使用此选项可能会导致大量提交被签名。使用代理来避免多次输入 GPG 密码可能会很方便。

As Apteryxcommented below:

正如Apteryx在下面评论的那样

To set this globally on the command line:

要在命令行上全局设置它:

git config --global commit.gpgsign true


With Git 2.27 (Q2 2020), "git rebase" learned the "--no-gpg-sign" option to countermand commit.gpgSignthe user may have.

在 Git 2.27(2020 年第二季度)中,“ git rebase”学会了“ --no-gpg-sign”选项来撤销commit.gpgSign用户可能拥有的选项。

See commit 5c5bac1, commit 4369d3a, commit 9da37fe, commit ae06ba6, commit cf0ad4d, commit c241371(03 Apr 2020) by ?oàn Tr?n C?ng Danh (``).
(Merged by Junio C Hamano -- gitster--in commit fc3f6fd, 22 Apr 2020)

请参阅?oàn Tr?n C?ng Danh (``) 的提交 5c5bac1提交 4369d3a提交 9da37fe提交 ae06ba6提交 cf0ad4d提交 c241371(2020 年 4 月 3 日
(由Junio C gitsterHamano合并-- --提交 fc3f6fd 中,2020 年 4 月 22 日)

cherry-pick/revert: honour --no-gpg-signin all case

Signed-off-by: ?oàn Tr?n C?ng Danh

{cherry-pick,revert} --edit hasn't honoured --no-gpg-sign yet.

Pass this option down to git committo honour it.

cherry-pick/revert: 荣誉--no-gpg-sign在所有情况下

签字人:?oàn Tr?n C?ng Danh

{cherry-pick,revert} --edit 尚未兑现 --no-gpg-sign 。

将此选项传递给以git commit兑现它。