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

ele*_*023 7 git github visual-studio

我在配置 Visual Studio 2022 以使用 SSH 或 GPG 密钥签署 GitHub 的 Git 提交时遇到问题。

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

git config --global user.signingkey 3AA5C34371567BD2
git config --global commit.gpgsign true
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在 Visual Studio 中进行提交时。

我收到以下错误:

Your Git hook is not supported. This is probably because the first line is not "#!/bin/sh".
Run Code Online (Sandbox Code Playgroud)

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

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

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

更新:

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

  1. 使用命令编辑 gitConfig 文件git config --global --edit
  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 中具有经过验证的标签。

Von*_*onC 6

Check first if this is similar to this thread, which, in 2019, added:

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