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

git config -l | grep gpg

如果它返回true,运行以下命令禁用它

git config --global --unset commit.gpgsign

成功运行上述命令后,应该可以运行git commit命令。

其他回答

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

如果gnupg2和gpg-agent 2。如果使用了x,请务必设置环境变量GPG_TTY。

export GPG_TTY=$(tty)

有关常见问题,请参阅GPG的文档。

我在构建最新的Git源代码(2.12.2)时遇到了类似的问题,同时还构建了所有依赖项的最新源代码(Zlib、Bzip、cURL、PCRE、ReadLine、IDN2、iConv、Unistring等)。

结果libreadline给GnuPG带来了问题:

$ gpg --version
gpg: symbol lookup error: /usr/local/lib/libreadline.so.7: undefined symbol: UP

当然,尝试用-vvv从Git中获取有用的信息失败了,所以失败是一个谜。

要解决由于ReadLine导致的PGP失败,请遵循不能更新或使用包管理器—gpg错误的说明:

在终端: ls /usr/local/lib 这里有很多readline lib (libreadline。so。blah - blah) 所以我: 苏 mkdir临时 Mv /usr/local/lib/libreadline* temp ldconfig

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

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

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

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

然后就成功了。