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

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

当前回答

当GPG密钥过期时,也会发生此错误。生成一个新密钥并将其添加到Git中应该可以解决这个问题。

其他回答

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

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

我正在使用Windows cygwin。

我已经做了一个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     ]

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

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

如果你使用的是windows powershell(5.1+),我想这个命令可以工作。

使用此命令获取GPG程序路径。

(Get-Command gpg).Path

在获取路径之后,复制路径。 使用这个命令

git config gpg.program <your path>

试着做出承诺。 编码快乐! !

如果它曾经工作,只是声明失败,杀死代理,再试一次:

gpgconf --kill gpg-agent

检查代理是否再次启动:

echo "test" | gpg --clearsign