我参考了几篇关于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

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


当前回答

我在Ubuntu 18.04上得到了同样的错误,也担心了几个星期。 最后意识到gpg2没有指向任何东西。 所以简单地运行

git config --global gpg.program gpg

然后,它就像魅力一样。

您的提交现在将带有验证标记。

其他回答

确保你的邮箱设置正确。

git config --global user.email "user@example.com"

我的解决方案是:

首先,我试图了解为什么这是行不通的细节。在终端上按cmd命令尝试

   $ echo "Hello" > test.txt
   $ gpg --sign --default-key <your-email-id> test.txt

观察到详细信息错误:gpg: signing failed: No pinentry

gpg-agent[59045]: can't connect to the PIN entry module '/usr/local/bin/pinentry': IPC connect call failed .日志含义 gpg-agent[59045]: failed to unprotect the secret key: No pinentry .日志含义

从终端我点击下面的cmd:

    cat ~/.gnupg/gpg-agent.conf

检查以下陈述是否存在。如果gpg-agent.conf中没有,需要添加

pinentry-program /usr/local/MacGPG2/libexec/pinentry-mac.app /内容/ MacOS / pinentry-mac

添加pinentry路径后,运行

    $ gpgconf --kill gpg-agent
    $ gpg --sign --default-key <your-email-id> test.txt

查看输出:

 gpg: using <your-email-id> as default secret key for signing

如果gnupg2和gpg-agent 2。如果使用了x,请务必设置环境变量GPG_TTY。

export GPG_TTY=$(tty)

有关常见问题,请参阅GPG的文档。

如果你不想处理brew来安装gpg,这似乎时不时会遇到问题,只需从gpg tools下载gpg工具。

在执行向导时,单击customize install并取消选择邮件插件(除非您想使用它)。这些工具似乎没有遇到任何问题,而且它会在你第一次签署提交后记住你的密码。不需要额外的配置,除了告诉git使用哪个键。

至少这是我的经验。

我用这个简单的食谱来做:

在macOS上自动签名提交(全局和不同的ide):

用这种方法获取签名密钥。

brew install gnupg gnupg2 pinentry-mac
git config --global user.signingkey <YOUR_SIGNING_KEY>
git config --global commit.gpgsign true
git config --global gpg.program gpg

将以下内容放入gpg.conf文件(使用nano ~/.gnupg/gpg.conf命令编辑文件):

no-tty

将以下内容放入gpg-agent.conf文件中(使用nano ~/.gnupg/gpg-agent.conf命令编辑文件):

pinentry-program /usr/local/bin/pinentry-mac

更新:

根据评论中的建议,您可能需要在编辑配置文件gpg.conf后执行killall gpg-agent命令。不用说,这个命令将终止GPG (Gnu Privacy Guard)代理。