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

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


当前回答

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

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

其他回答

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>"

然后就成功了。

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

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

$ GPG—编辑键

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

按照下面的url设置签名提交 https://help.github.com/en/articles/telling-git-about-your-signing-key

如果还在 GPG签署数据失败致命: 日志含义写提交对象失败

这不是git的问题,而是GPG的问题 遵循以下步骤

gpg——版本 回显"test" | GPG—clearsign

如果显示:

gpg: signing failed: Inappropriate ioctl for device
gpg: [stdin]: clear-sign failed: Inappropriate ioctl for device

然后使用export GPG_TTY=$(tty) 然后再次尝试echo“test”| GPG—clearsign 得到PGP签名。 Git config -l | grep GPG

gpg.program=gpg
commit.gpgsign=true

应用git commit -m "commitMsz"

我的观点是:

当您创建并向gpg-agent添加密钥时,您定义了称为passphrase的东西。现在这个密码短语在某个时候到期了,gpg需要您再次输入它来解锁密钥,以便您可以再次开始签名。

当您使用任何其他与gpg接口的程序时,gpg提示您输入您的密码短语不会出现(基本上gpg-agent在守护时不可能在stdin中显示输入对话框)。

其中一个解决方案是gpg——sign a_file.txt,然后输入您在创建密钥时输入的密码,然后一切都应该正常(gpg-agent应该自动签名)

关于如何为密码短语设置更长的超时,以便您不必一直这样做,请参阅此答案。

或者您可以使用ssh-keygen -p完全删除密码短语

编辑:做一个man gpg-agent来阅读一些关于如何自动发生上述情况的内容,并添加以下行:

GPG_TTY=$(tty)
export GPG_TTY

如果你正在使用bash(这是正确的答案,但我也保持我的思路),然后来源你的.bashrc文件或重新登录。

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对象,该对象处理 对我们来说困难的案子,再加上失踪的清理电话。