我参考了几篇关于Git 2.10发行说明中的漂亮属性的文章。将git升级到2.10.0,并对全局的.gitconfig进行了更改,结果如下-

[filter "lfs"]
    clean = git-lfs clean %f
    smudge = git-lfs smudge %f
    required = true
[user]
    name = xyz
    email = abc.def@gmail.com
    signingkey = AAAAAAA
[core]
    excludesfile = /Users/xyz/.gitignore_global
    editor = 'subl' --wait
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
[color "diff"]
    old = red strike
    new = green italic

但是现在我尝试使用

git commit -a -S -m "message"

我看到下面的错误-

你需要一个密码来解锁秘钥 用户:“XYZ(数字签名)” 2048-bit RSA key, ID AAAAAAAA, created 2016-07-01 错误:GPG数据签名失败致命:写提交失败 对象

注意-我仍然可以使用git commit -a -m "message"来提交更改

有办法克服同样的问题吗?或者在gpg配置中需要做任何改变以适应git的升级?


更新1

还寻求进一步的有用性,以下是是否有一种方法在Git中使用GPG密钥“自动签名”提交?我已经配置了密钥使用

git config --global user.signingkey ED5CDE14(with my key) 
git config --global commit.gpgsign true

很明显得到了相同的错误。


当前回答

如果在没有Rosetta的M1芯片上使用自制程序,则需要为pin - entry程序二进制文件指定不同的位置,因为它安装在不同的位置。

Andy Hayden的更新答案需要修改如下:

brew upgrade gnupg  # This has a make step which takes a while
arch -arm64 brew link --overwrite gnupg
arch -arm64 brew install pinentry-mac
echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

其他回答

对我来说,brew已经更新了gnupg或gpg,所以我所要做的就是解决这个问题。

brew link --overwrite gnupg

这将gpg链接到正确的位置,因为我可以确认通过哪个gpg和之后的一切工作。

如果与GPG密钥的uid相关联的电子邮件与您在git中使用的电子邮件不同,则需要向密钥添加另一个用户id,或者使用与电子邮件完全匹配的密钥。

您可以通过以下方式添加另一个UID:

$ GPG—编辑键

见莫https://superuser.com/questions/293184/one-gnupg-pgp-key-pair-two-emails

我在Ubuntu 18.04上得到这个错误,原来我的密钥过期了。

为了看到这个,我运行了这个,它确认我的密钥过期了:

gpg --list-keys

为了纠正这个错误,我运行(使用之前命令中显示的ID):

gpg --edit-key <ID>

从那里,我延长了键0和键1的过期时间,遵循这些指令,最后输入键0,然后过期,并按照提示进行操作。然后重复键1。

之后,为了测试这一点,我运行:

echo test | gpg --clearsign

在修复之前,它失败了,错误如下:

gpg: no default secret key:无默认密钥 gpg: [stdin]: clear-sign failed: No secret key

但是在修复之后,相同的命令成功地对消息进行了签名,所以我知道事情又开始工作了!

我在构建最新的Git源代码(2.12.2)时遇到了类似的问题,同时还构建了所有依赖项的最新源代码(Zlib、Bzip、cURL、PCRE、ReadLine、IDN2、iConv、Unistring等)。

结果libreadline给GnuPG带来了问题:

$ gpg --version
gpg: symbol lookup error: /usr/local/lib/libreadline.so.7: undefined symbol: UP

当然,尝试用-vvv从Git中获取有用的信息失败了,所以失败是一个谜。

要解决由于ReadLine导致的PGP失败,请遵循不能更新或使用包管理器—gpg错误的说明:

在终端: ls /usr/local/lib 这里有很多readline lib (libreadline。so。blah - blah) 所以我: 苏 mkdir临时 Mv /usr/local/lib/libreadline* temp ldconfig

对于在MacOS机器上遇到此问题的任何人,请尝试以下方法:

brew uninstall gpg brew install gpg2 brew install pinentry-mac (if needed) gpg --full-generate-key Create a key by using an algorithm. Get generated key by executing: gpg --list-keys Set the key here git config --global user.signingkey <Key from your list> git config --global gpg.program /usr/local/bin/gpg git config --global commit.gpgsign true If you want to export your Key to GitHub then: gpg --armor --export <key> and add this key to GitHub at GPG keys: https://github.com/settings/keys (with START and END line included)

如果问题仍然存在:

Test -r ~/。bash_profile && echo 'export GPG_TTY=$(tty)' >> ~/.bash_profile

echo 'export GPG_TTY=$(tty)' >> ~/.profile

如果问题仍然存在:

安装https://gpgtools.org并通过从菜单栏按下sign来签署您使用的密钥:key -> sign

如果问题仍然存在:

转到:⁨你的全局。gitconfig文件,在我的例子中是:⁨/Users/gent/.gitconfig 并修改.gitconfig文件(请确保Email和Name与您在生成Key时创建的相同):

(用户) 邮箱= gent@youremail.com name = Gent signingkey = <YOURKEY> (gpg) 程序= /usr/local/bin/gpg (提交) Gpsign = true Gpgsign = true (过滤“lfs”) Process = git-lfs filter-process Required = true 清洁= git-lfs清洁——%f 涂抹= git-lfs涂抹——%f (证书) Helper = osxkeychain