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

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


当前回答

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

brew link --overwrite gnupg

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

其他回答

我在OSX上遇到了这个问题。

最初的回答:

这似乎是一个gpg更新(brew)改变了gpg的位置到gpg1,你可以改变二进制的git查找gpg:

git config --global gpg.program gpg1

如果没有gpg1: brew,请安装gpg1。

答:更新

看起来gpg1被弃用了/“慢慢地退出使用”,所以你可能真的应该更新到gpg2,不幸的是这涉及到相当多的步骤/一点时间:

brew upgrade gnupg  # This has a make step which takes a while
brew link --overwrite gnupg
brew install pinentry-mac

在老的自制啤酒上:

echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
killall gpg-agent

在M1 mac等较新的系统上:

echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf 
killall gpg-agent

第一部分安装gpg2,后一部分是使用它所需的hack。关于故障排除,请参阅这个答案(虽然这是关于linux而不是brew),它建议一个很好的测试:

echo "test" | gpg --clearsign  # on linux it's gpg2 but brew stays as gpg

如果此测试成功(没有包含PGP签名的错误/输出),则您已经成功更新到最新的gpg版本。

现在您应该可以再次使用git签名了! 值得注意的是,你需要:

git config --global gpg.program gpg  # perhaps you had this already? On linux maybe gpg2
git config --global commit.gpgsign true  # if you want to sign every commit

注意:在你运行了一个有签名的提交之后,你可以验证它的签名:

git log --show-signature -1

其中将包括最后一次提交的GPG信息。

在使用cygwin时,我最近改用了gpg2。然后,在设置git config gpg后,我也遇到了同样的问题。程序gpg2。

尝试echo "test" | gpg2——clearsign查看gpg2是否正常工作。我发现这是最简单的解决方案,只是设置git配置gpg。编写gpg,因为这是可行的。但你也会得到一个更好的错误这种方式-例如,你需要安装pinentry。

我的解决方案是:

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

我一定是不小心更新了gpg,因为我在尝试测试gpg是否工作后得到了这个:

gpg: WARNING: server 'gpg-agent' is older than us (2.1.21 < 2.2.10)
gpg: Note: Outdated servers may lack important security fixes.
gpg: Note: Use the command "gpgconf --kill all" to restart them.

运行gpgconf—kill all为我解决了这个问题。

git的痕迹非常暴露了我的情况……

   GIT_TRACE=1 git commit -m "a commit message"
   13:45:39.940081 git.c:344               trace: built-in: git commit -m 'a commit message'
   13:45:39.977999 run-command.c:640       trace: run_command: gpg --status-fd=2 -bsau 'full name <your-email@domain.com>'
   error: gpg failed to sign the data
   fatal: failed to write commit object

我需要根据git检查的格式生成一个初始密钥。最好在日志中复制上面传递给-bsau的值,然后在下面使用。

所以它变成了,

   gpg --quick-generate-key "full name <your-email@domain.com>"

然后就成功了。