我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?

error: gpg failed to sign the data
fatal: failed to write commit object

当前回答

我刚刚在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。

参考@sideshowbarker和@Xavier Ho解决方案,我通过以下步骤解决了我的问题。

假设gpg2通过brew安装,

git config --global gpg.program gpg2
brew install pinentry
gpgconf --kill gpg-agent
gpg2 -K --keyid-format SHORT
// no key found then generate new one
gpg2 --gen-key

gpg2 -K --keyid-format SHORT 

           

... - dpg gnupg - pubring。

sec rsa2048/0A61C6FC 2017-06-29 [SC][有效期:2019-06-29]

git config --global user.signingkey 0A61C6FC

经同事提醒,需要追加

export GPG_TTY=$(tty)

~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile


For macOS,

gpg2在brew中与GPG结合,因此GPG命令指向gpg2

brew install gpg2

酿造信息GPG

Gnupg:稳定2.2.6(瓶装)

git config --global gpg.program gpg
gpg -K --keyid-format SHORT 

还有pinentry-mac用于密码输入

brew install pinentry-mac
vim ~/.gnupg/gpg-agent.conf

添加一行

pinentry-program /usr/local/bin/pinentry-mac

经同事提醒,需要追加

export GPG_TTY=$(tty)

~ /。ZSHRC如果使用zsh,否则追加到~/.bash_profile

我在linux/windows平台上都有这个问题,在我的情况下,我只需要更仔细地注意输出。这是令人难以置信的,因为我可以使用相同的设置在其他回购中签署提交。

git commit -m "test signing"
gpg: skipped "***63231079***": No secret key
gpg: signing failed: No secret key
error: gpg failed to sign the data
fatal: failed to write commit object

我强调了“跳过”这一行。请注意,有时当你克隆一个回购时,他们会分配一个密钥:这个问题让我很困惑,以至于我破坏了我可以访问的分叉回购,并在github上重新分叉。然后因为我在想“全局配置”,我从来没有想过要看本地回购配置,当我注意到这一点:

[user]
    signingkey = 63231079

嗯,当然它不会工作nimrod, git默认为本地设置,所以这就是为什么你的密钥永远不会被拾取。我通过git配置设置指针,它一直在工作。

对我来说,一个简单的brew卸载gnupg && brew桶重新安装gpg-suite解决了这个问题。

它会手动卸载(在我的情况下)自定义安装的gpg,并重新安装整个gpg套件。

我必须修好gpg。编程到gpg的绝对路径:

git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"

我正在使用Windows cygwin。