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

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

当前回答

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

其他回答

什么是gpg: GNU Privacy Guard

用法:

GPG是确保双方安全通信的一种极好的方法。它允许敏感信息在不安全的网络上轻松共享。

简单的解决方案:

步骤1:检查密钥是否过期请做

gpg -K——keyid-format SHORT

步骤2:如果它没有过期

Git配置——global user.signingkey

我正在使用它。它支持zsh和工作在Windows子系统Linux:

export GPG_TTY=$(tty)

其他用户已经确认以上是MacOS(例如Catalina 10.15.7)所需的唯一更改。对于mac,将以上内容添加到~/.zshrc。

在使用WSL2的Windows中的Linux容器中也可以工作。

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

参考@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配置中的key过期时,同样的错误也会引起。

请检查cat .git/config的内容,查找signingkey value是否过期。如果是,更新为新的。