我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
当前回答
当你的git配置中的key过期时,同样的错误也会引起。
请检查cat .git/config的内容,查找signingkey value是否过期。如果是,更新为新的。
其他回答
对我来说,一个简单的brew卸载gnupg && brew桶重新安装gpg-suite解决了这个问题。
它会手动卸载(在我的情况下)自定义安装的gpg,并重新安装整个gpg套件。
我刚刚在VSCode更新时遇到了这个问题。我认为GPG代理挂起了,因为该命令在出错之前运行了几秒钟。运行gpgconf——kill gpg-agent重置并为我修复了它。
Git需要知道它是用哪个密钥签名的。
在您设置了GPG、GPG -agent和GPG .conf文件(请参阅本指南)之后,您需要运行
git config --global user.signingKey EB11C755
显然,要用您自己的公钥替换最后的公钥。如果您希望在默认情况下对每个提交进行签名,请使用
git config --global commit.gpgsign true
$ gpg2 -K --keyid-format SHORT # <-- Shows your keys, e.g.:
/home/<username>/.gnupg/pubring.kbx
-------------------------------
sec rsa4096/0754B01E 2019-02-02 [SCA] <--secret key
C396BF3771782D7691B0641145E11B080754B01E
uid [ultimate] John Doe <user@domain.com>
ssb rsa4096/A20AB8EC 2019-02-02 [E] <--public key
sec rsa4096/25C504D5 2019-02-02 [SCA] [revoked: 2020-06-01]
08BFF49B9E07E4B4B0C4946B645B6C1425C504D5
uid [ revoked] John Doe <user2@domain.com>
uid [ revoked] [jpeg image of size 2670]
其中A20AB8EC是本例中要查找的键ID。
这在ubuntu 18.04上对我有效
检查你的gpg密钥
gpg -K --keyid-format LONG
如果得到空白响应,则生成一个GPG密钥
gpg --generate-key
重新运行第一个命令,你应该得到一个输出:
sec rsa3072/95A854E0593B3214 2019-05-06 [SC] [expires: 2021-05-05]
AF2F7514568DC26B0EB97B9595A854E0593B74D8
uid [ultimate] yourname<your_email>
ssb rsa3072/EFD326E6C611117C 2019-05-06 [E] [expires: 2021-05-05]
设置git签名密钥
git config --global user.signingkey 95A854E0593B3214
然后你就可以开始了!(——global是可选的)
或者,如果您不介意用ssh密钥签名
git config commit.gpgsign false
请注意,由于这里和这里的问题存在安全问题,不建议这样做
在我的例子中,当在一个小的tmux窗口上运行git提交时,这个错误发生了,这个窗口不能适合密码短语提示。
$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
test
gpg: signing failed: Screen or window too small
gpg: [stdin]: clear-sign failed: Screen or window too small