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

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


当前回答

我的观点是:

当您创建并向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文件或重新登录。

其他回答

可能有助于杀死进程gpg-agent可能卡住旧数据。因此,新启动的gpg-agent将要求输入密码。

确保你的邮箱设置正确。

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

如果你的问题是Visual Studio Code不允许提交,但你已经设置了你的GPG签名,用bash的一行答案是:

git config --global gpg.program `which gpg2`

如果你在PATH中有gpg,但没有gpg2,那么就用它来代替。

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

我在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信息。