Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

gnupg - Git error - gpg failed to sign data

I just started using git and I install git and gpg via homebrew. For some reason, I get this error when i do git commit I looked at so many other stackoverflow questions regarding this topic and none of them worked for me. How can I fix this error so that I can upload successfully.

error: gpg failed to sign the data
fatal: failed to write commit object
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For troubleshooting, two things to first try:

  • run git config --global gpg.program gpg2, to make sure git uses gpg2 and not gpg
  • run echo "test" | gpg2 --clearsign, to make sure gpg2 itself is working

If that all looks all right, one next thing to try:

  • run brew install pinentry to ensure you have a good tool installed for passphrase entry

If after that install, you re-try git commit and still get a "failed to sign the data" error, do:

  • run gpgconf --kill gpg-agent to kill any running agent that might be hung

If that says gpgconf isn’t installed or doesn’t have a --kill option, you might try this:

  1. cp ~/.gnupg ~/.gnupg-GOOD to save a copy of your ~/.gnupg to revert to later if needed
  2. brew install gnupg21 to install GnuPG 2.1

The reason for saving a copy of your ~/.gnupg dir is, GnuPG 2.1 potentially creates/changes some key data in way that isn’t backward-compatible with GnuPG 2.0 and earlier, so if you want to go back later, you can do mv ~/.gnupg ~/.gnupg21 && mv ~/.gnupg-GOOD ~/.gnupg.


Otherwise, some basic steps to run to check you’ve got a working GnuPG environment:

  • run gpg2 -K --keyid-format SHORT, to check that you have at least one key pair

If the output of that shows you have no secret key for GnuPG to use, you need to create one:

  • run gpg2 --gen-key, to have GnuPG walk you through the steps for creating a key pair

If you get an error message saying “Inappropriate ioctl for device”, do this:

  • run export GPG_TTY=$(tty) and/or add that to your ~/.bashrc or ?/.bash_profile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...