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

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

当前回答

如果您使用智能卡/yubikey存储您的GPG密钥,并且您通过存储在卡中的密钥设置了git配置的signkey(并且上面所有的答案似乎都不能解决您的问题),您的卡的PIN被阻塞可能是这个问题的根本原因。

检查被阻止的PIN码:

gpg --card-status

如果计数器类似于

Reader ...........: Yubico YubiKey
PIN retry counter : 3 0 3

然后你的PIN被阻止(3次不成功尝试后)。

解锁密码:

gpg --card-edit
gpg/card> admin
Admin commands are allowed

gpg/card> passwd
gpg: OpenPGP card no. … detected

1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit

Your selection? 2
PIN unblocked and new PIN set.

1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit

Your selection? q

其他回答

在我的情况下,我必须将存储在GitHub设置中的名称与键的名称和注释匹配。

所以如果gpg——list-keys返回uid [ultimate] Joe Blogs(花式注释)<email@example.com>你在.gitconfig中的名字应该是Joe Blogs(花式注释)。

最初,我将自己的名字设置为Joe Blogs, GPG不会找到我的密钥,并在strace中显示“无密钥”错误。不幸的是,如果没有strace,该错误就不会出现,并且会得到泛型

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

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

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

我正在使用Windows cygwin。

我解决了安装brew install gpg2然后做git配置——global gpg的问题。程序gpg2

如果您使用智能卡/yubikey存储您的GPG密钥,并且您通过存储在卡中的密钥设置了git配置的signkey(并且上面所有的答案似乎都不能解决您的问题),您的卡的PIN被阻塞可能是这个问题的根本原因。

检查被阻止的PIN码:

gpg --card-status

如果计数器类似于

Reader ...........: Yubico YubiKey
PIN retry counter : 3 0 3

然后你的PIN被阻止(3次不成功尝试后)。

解锁密码:

gpg --card-edit
gpg/card> admin
Admin commands are allowed

gpg/card> passwd
gpg: OpenPGP card no. … detected

1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit

Your selection? 2
PIN unblocked and new PIN set.

1 - change PIN
2 - unblock PIN
3 - change Admin PIN
4 - set the Reset Code
Q - quit

Your selection? q

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

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