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

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


当前回答

我的解决方案是:

首先,我试图了解为什么这是行不通的细节。在终端上按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

其他回答

我在Ubuntu上突然开始出现这种情况,不确定是不是最近的一些更新做到了,但没有一个现有的问题适用于我(我设置了GPG_TTY,尝试杀死代理等)。独立的gpg命令失败,错误如下:

$ echo "test" | gpg --clearsign
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

test
gpg: signing failed: Operation cancelled
gpg: [stdin]: clear-sign failed: Operation cancelled

我试着用——debug-all选项运行gpg,注意到下面的输出:

gpg: DBG: chan_3 <- INQUIRE PINENTRY_LAUNCHED 27472 gnome3 1.1.0 /dev/pts/6 screen-256color -
gpg: DBG: chan_3 -> END
gpg: DBG: chan_3 <- ERR 83886179 Operation cancelled <Pinentry>
gpg: signing failed: Operation cancelled

以上说明pinentry程序存在一些问题。Gpg通常会为我运行pinentry-curses,所以我把它改成了pinentry-tty(我必须先安装它),错误就消失了(尽管我不再得到全屏密码输入,但我不喜欢这样)。为了做出这个改变,我必须在~/.gnupg/gpg-agent.conf中添加一行pinentry-program /usr/bin/pinentry-tty,并使用gpgconf——kill gpg-agent来杀死代理(它会在下次重新启动)。

我的解决方案是:

首先,我试图了解为什么这是行不通的细节。在终端上按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

在我的例子中,其他答案中提到的解决方案都不起作用。我发现这个问题特定于一个存储库。删除和克隆回购再次解决了这个问题。

我也遇到了同样的问题。我很高兴地报告,问题不在于git 2.10.0,而在于gnupg 1.4.21。

暂时将gnupg降级到1.4.20为我解决了这个问题。

如果你正在使用自制程序,并且像我一样升级了你的包,你可能只需要运行brew开关gnupg 1.4.20来恢复。

我在构建最新的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