GIT 提交错误 - WSL2 中的 VSCODE(错误:gpg 未能签署数据致命:无法写入提交对象)

时间:2021-02-09 10:16:10

标签: git visual-studio-code git-commit gnupg

我已经安装了 VSCode

code --version
<块引用>

1.53.0 8490d3dde47c57ba65ec40dd192d014fd2113496 x64 Git 版本:

git --version
<块引用>

git 版本 2.27.0

我有活动密钥。当我提交时,我收到标题错误。我在命令行中收到错误并在 vscode 中单击提交。

GIT_TRACE=1 git commit -m "start"
<块引用>

11:50:45.606604 git.c:442 跟踪:内置:git commit -m 开始 11:50:45.649422 run-command.c:663 跟踪:run_command: /usr/bin/gpg --status-fd=2 -bsau “主动键”

错误:gpg 未能对数据进行签名

致命:无法写入提交对象

gpg --status-fd=2 -bsau "active key"
<块引用>

[GNUPG:] KEY_CONSIDERED“活动密钥”2

[GNUPG:] BEGIN_SIGNING H10

^C

gpg:信号中断捕获...退出

它一直挂到我停下来。 有任何想法吗?。谢谢。

2 个答案:

答案 0 :(得分:0)

我在 WSL2(unbuntu 20.04)下遇到了类似的问题,并且能够重现您的错误。

初始情况:

GPG 密钥可用。但要注意有许多过时的说明,因此请使用:https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key

gpg --full-generate-key 就我而言

解决方案:

  1. 您将 git 与配置的 commit.gpgsign = true 一起使用,因为您在 UI 和控制台中收到错误。 如果不需要,则在项目文件夹中本地停用签名: git config commit.gpgsign false 或全球 git config --global commit.gpgsign false

  2. 您想签署并使用 VSCode。 问题的核心是 WSL2 中的 GPG 安装,因为这就是使用的。 GPG 代理丢失,Windows 无法解锁密钥。在 WSL2 中安装代理并配置它。只要在 WSL2 终端下激活 GPG 密钥,就可以使用缓存状态。然后 VSCode 将在配置的时间内工作。 如果您想在 Windows 下输入密码,请阅读此处的解决方案:No GPG passphrase prompt in Visual Studio Code on Windows 10 for signed git commits using WSL2

答案 1 :(得分:0)

我按照这些说明成功修复了我的 WSL2 设置https://www.39digits.com/signed-git-commits-on-wsl2-using-visual-studio-code

最重要的是在Windows 10中安装GPG4Win...并添加~/.gnupg/gpg-agent.conf

default-cache-ttl 34560000
max-cache-ttl 34560000
pinentry-program "/mnt/c/Program Files (x86)/GnuPG/bin/pinentry-basic.exe"
<块引用>

Visual Studio Code 安装在 Windows 10 端,因此我们 提交时需要该图形 pinentry 输入密码 来自编辑器的代码。