我参考了几篇关于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上得到这个错误,原来我的密钥过期了。

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

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_TRACE=1显示了git实际在做什么:

$ GIT_TRACE=1 git commit -m "example commit message"
20:52:58.902766 git.c:328               trace: built-in: git 'commit' '-vvv' '-m' 'example commit message'
20:52:58.918467 run-command.c:626       trace: run_command: 'gpg' '--status-fd=2' '-bsau' '23810377252EF4C2'
error: gpg failed to sign the data
fatal: failed to write commit object

现在手动运行失败命令:

$ echo "dummy" | gpg -bsau 23810377252EF4C2
gpg: skipped "23810377252EF4C2": Unusable secret key
gpg: signing failed: Unusable secret key

原来我的钥匙过期了,这不是我的错。

如果这只是随机发生的,并且在过去一直工作得很好,就像我的情况一样,尝试注销(cmd+shift+q)并重新登录。为我工作

我得到这个错误,每次登出,然后再次登录我的macOS。解决方案只是一个简单的命令:

killall gpg-agent

我认为这只是gpg代理的一个错误,杀死它,然后重新工作。

2016年10月更新:第871期提到“Git 2.9.3中签名停止工作”

Git for Windows 2.10.1于两天前(2016年10月4日)发布,修复了提交和标记的交互式GPG签名。

git中最近的gpg-sign更改(在Linux上没有问题)暴露了一个问题,即在Windows上,非msys2 -git与MSYS2-gpg交互的方式。


最初的回答:

阅读“7.4 Git工具-签名你的工作”,我假设你有你的“用户”。Signingkey”配置集。

最后一次围绕gpg的大重构(在Git 2.10之前)是在提交2f47eae2a,在这里错误消息被移动到gpg-interface.c

该文件的日志显示了提交af2b21e (Git 2.10)中最近的更改

gpg2 already uses the long format by default, but most distributions seem to still have "gpg" be the older 1.x version due to compatibility reasons. And older versions of gpg only show the 32-bit short ID, which is quite insecure. This doesn't actually matter for the verification itself: if the verification passes, the pgp signature is good. But if you don't actually have the key yet, and want to fetch it, or you want to check exactly which key was used for verification and want to check it, we should specify the key with more precision.

因此,请检查您如何指定用户。签名密钥配置和正在使用的GPG版本(gpg1或gpg2),以查看它们是否对错误消息有任何影响。

还有提交0581b54,它改变了gpg未能签署数据错误消息的条件(作为提交0d2b664的补充):

我们目前根本不从stderr读取。然而,在未来的补丁中,我们会想要这样做,所以这也为我们做好了准备(在这种情况下,gpg确实会在读取所有输入之前写入,尽管同样,键uid不太可能填满管道缓冲区)。

提交4322353显示gpg现在使用临时文件,因此可能存在正确的问题。

让我们转换为使用tempfile对象,该对象处理 对我们来说困难的案子,再加上失踪的清理电话。

对于在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