我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
我刚开始使用git,我通过自制软件安装git和gpg。 由于某种原因,当我提交git时,我得到了这个错误 我看了很多关于这个话题的stackoverflow问题,但没有一个对我有用。 如何修复此错误以成功上传?
error: gpg failed to sign the data
fatal: failed to write commit object
当前回答
我在macos上出现了这个错误-为了尝试和排除故障,我尝试使用gpg2—list-keys列出密钥,看看它们是否已经过期-我验证了密钥没有过期,并且使用git config—global user.signingkey在我的配置中设置了正确的密钥。
在我运行这些命令之后,我突然能够再次毫无问题地进行签名提交。我没有改变我的配置文件或密钥-我甚至没有创建一个新的终端实例。我的mac上的gpg2似乎处于一种奇怪的状态。
其他回答
使用GIT_TRACE=1查看Git失败的地方,然后检查Git使用的所有自定义配置以及它们定义的地方,然后根据您的需要覆盖:
GIT_TRACE=1 git commit -S -m "this will tell you wich intern git command failed"
git config --list --show-scope --show-origin
对我来说,我有错误:gpg未能签署数据和致命:未能写入提交对象,因为Git默认使用smimesign,即使我取消设置gpg.x509。程序钥匙,smimesign找不到我的钥匙。
所以我必须显式地告诉Git使用gpg:
git config --local gpg.x509.program gpg
对于故障排除,首先要尝试两件事:
运行gpg——version,并确保安装了GnuPG版本2+(而不是版本1) 执行echo "test" | GPG——clearsign命令,确认GPG本身在工作
如果一切看起来都没问题,接下来要尝试的一件事是:
运行brew install pinentry以确保您已经安装了用于密码短语输入的良好工具
如果在安装之后,你再次尝试git提交,仍然得到一个“failed to sign the data”错误,请执行:
执行gpgconf——kill gpg-agent命令杀死任何可能挂起的正在运行的代理
否则,运行一些基本步骤来检查你是否有一个正常工作的GnuPG环境:
执行gpg -K——keyid-format SHORT命令,检查至少有一个密钥对没有过期
如果输出显示你没有供GnuPG使用的密钥,你需要创建一个:
运行gpg——gen-key,让GnuPG引导您完成创建密钥对的步骤
如果你得到一个错误消息说“不合适的ioctl为设备”,这样做:
运行export GPG_TTY=$(tty)和/或将其添加到~/。Bashrc或~ /.bash_profile
参考@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假
可能你的Git配置设置为gpgsign = true。如果你不想指定你的提交,试着把它设置为false。转到存储库文件夹并更改该文件
纳米git -配置。
从这个……
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@bitbucket.org:yourrepo/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
signingkey = <GPG-KEY>
[commit]
gpgsign = true
这……
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@bitbucket.org:yourrepo/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[user]
signingkey = <GPG-KEY>
[commit]
gpgsign = false