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

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

当前回答

我已经做了一个git密钥,有3个单独的密钥用于认证/签名/加密&密钥在未来显示过期(在正常工作几天后):

pub   rsa4096/4CD1E9DA 2017-04-26 [C] [expired: 2017-04-28]
      Key fingerprint = 4670 59C1 7592 08B8 7FA5  313B 2A42 B6A6 4CD1 E9DA
uid         [ expired] Stuart Cardall (GIT Development Keys) <xxxxxx>
sub   rsa4096/5195E715 2017-04-26 [E] [expired: 2019-04-26]
sub   rsa4096/DB74C297 2017-04-26 [S] [expired: 2019-04-26]
sub   rsa2048/A3913A3C 2017-04-28 [] [expired: never     ]

在不添加单独子键的情况下创建一个新键来解决问题。

其他回答

我解决了安装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

对我有用的故障安全措施:重启我的机器。

这种做法很严厉,而且最终可能无法阻止问题再次出现。但我也遇到了同样的问题,尝试了几乎所有答案的解决方案,但运气不佳。

在这里添加它,希望它能解除其他人在我的情况:)

参考@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

这将帮助你摆脱它

Git配置提交。gpgsign假