如何配置Visual Studio 2022使用SSH或GPG密钥为GitHub签署Git提交?

5

我在配置Visual Studio 2022使用SSH或GPG密钥为GitHub签署Git提交方面遇到了问题。

我尝试使用以下命令设置GPG签名:

git config --global user.signingkey 3AA5C34371567BD2
git config --global commit.gpgsign true

然而,当我在Visual Studio中尝试提交时。

我会收到以下错误:

Your Git hook is not supported. This is probably because the first line is not "#!/bin/sh".

我检查了.git/hooks目录中的所有文件,它们的第一行都是#!/bin/sh

如果我不设置git config --global commit.gpgsign true,提交会通过,但在GitHub上标记为未验证。

如何正确配置Visual Studio使用SSH或GPG密钥为GitHub签署Git提交?任何帮助将不胜感激。

更新:

我找到了一个在Visual Studio 2022中使用SSH签署提交的解决方案。以下是我遵循的步骤:

  1. 使用命令git config --global --edit编辑gitConfig文件。
  2. 添加以下行:[gpg "ssh"] sshCommand = C:/Windows/System32/OpenSSH/ssh.exe
  3. 运行以下命令:git config --global gpg.format sshgit config --global user.signingkey /C:/Users/Admin/.ssh/id_signinged25519.pubgit config --global commit.gpgsign true

现在,当我使用Visual Studio进行PUSH时,在GitHub上提交将具有已验证的标签。

1个回答

3

首先检查一下这是否类似于this thread,该帖子在2019年添加了以下内容:

必须运行git config --global gpg.program "C:\Program Files\Git\usr\bin\gpg.exe"命令或安装gpg.exe的路径。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接