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

然后就成功了。

在我的例子中,问题在于~/.gitconfig中gpg的相对名称。我把它改成这样,问题就消失了(蒙特雷,Macbook M1):

[gpg]
    program = /opt/homebrew/bin/gpg

解释很简单:当git试图运行gpg时,它在一个新的shell中运行,而不运行~/。我为自制程序配置PATH的配置文件。所以,它根本找不到gpg。

我一定是不小心更新了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为我解决了这个问题。

如果你不想处理brew来安装gpg,这似乎时不时会遇到问题,只需从gpg tools下载gpg工具。

在执行向导时,单击customize install并取消选择邮件插件(除非您想使用它)。这些工具似乎没有遇到任何问题,而且它会在你第一次签署提交后记住你的密码。不需要额外的配置,除了告诉git使用哪个键。

至少这是我的经验。

我在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来杀死代理(它会在下次重新启动)。