bash 在 Windows 上为 Git 配置 GPG

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46992596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 16:33:48  来源:igfitidea点击:

Configure GPG for Git on Windows

gitbashcharacter-encodinggnupgpgp

提问by just.me

I installed Git for Windows including Git Bash on Windows 10 and Gpg4win. By default, I had to re-import all keys I created via Kleopatra into the GPG version built into the Git Bash, and it won't allow me to setup an agent. What I need to do is to automate singing such that I don't need to enter the password every single time, but rather only the first time in a given period of time. How is that possible?

我在 Windows 10 和 Gpg4win 上安装了适用于 Windows 的 Git,包括 Git Bash。默认情况下,我必须将我通过 Kleopatra 创建的所有密钥重新导入 Git Bash 中内置的 GPG 版本,并且它不允许我设置代理。我需要做的是自动唱歌,这样我就不需要每次都输入密码,而是在给定的时间段内第一次输入密码。这怎么可能?

I tried to follow this tutorial, but gpg2 does not use the correct charset when executed from within Git Bash, so it does not recognize keys which contain non-ASCII characters.

我尝试按照本教程进行操作,但是从 Git Bash 中执行时 gpg2 不使用正确的字符集,因此它无法识别包含非 ASCII 字符的键。

Is there any way to solve this problem? What is the best way to use PGP signing with Git on Windows?

有没有办法解决这个问题?在 Windows 上通过 Git 使用 PGP 签名的最佳方法是什么?

回答by VonC

Update Oct. 2018, as commented belowby PHPirate:

更新 2018 年 10 月,正如PHPirate在下面评论那样

λ git --version
git version 2.19.1.windows.1

λ gpg --version
gpg (GnuPG) 2.2.9-unknown
libgcrypt 1.8.3
Copyright (C) 2018 Free Software Foundation, Inc.

No trace of that update in git-for-windows/git/releases

没有任何更新的痕迹 git-for-windows/git/releases



Original answer (2017): By default, Git for Windows includes a gpg1, not gpg2

原始答案(2017):默认情况下,Git for Windows 包含 gpg1,而不是 gpg2

vonc@bvonc MINGW64 ~/.ssh
$ gpg --version
gpg (GnuPG) 1.4.21

Using a different gpg is indeed recommended:

确实建议使用不同的 gpg:

git config --global gpg.program "c:/Program Files (x86)/GnuPG/bin/gpg.exe"

Try again with the latest Git for Windowswith UTF-8 set in locale.
Try a Git simplified pathto rule out any interference from other programs.

使用在 locale 中设置UTF-8最新版 Git for Windows再试一次。 尝试使用Git 简化路径以排除来自其他程序的任何干扰。

回答by PHPirate

Since (at least) git 2.19.1, git includes gpg2!

从(至少)git 2.19.1 开始,git 包括 gpg2!

That means you are not required to install gpg4win anymore just for git signing. You ask how to setup commit signing such that you only have to enter your passphrase after a certain timeout: gpg-agentcan handle that, and I tested that it works with git's gpg (but not with gnupg's gpg). Although it doesn't always work for me, it should work in general.

这意味着您不再需要仅为 git 签名而安装 gpg4win。您询问如何设置提交签名,以便您只需要在特定超时后输入密码:gpg-agent可以处理这个问题,并且我测试了它是否适用于 git 的 gpg(但不适用于 gnupg 的 gpg)。虽然它并不总是对我有用,但它应该适用于一般情况。

Below is a short summary of the full instructions I have written down here, assuming you have signing set up:

以下是我在此处写下的完整说明的简短摘要,假设您已设置签名:

  1. Make sure you are using git's gpg
  2. Update the cache time, in C:\Users\username\.gnupg\gpg-agent.conf(create the file if it doesn't exist), add default-cache-ttl 34560000and max-cache-ttl 34560000. These times are in seconds, choose whatever you want.
  3. Restart gpg-agent using gpgconf --kill gpg-agent.
  1. 确保你使用的是 git 的 gpg
  2. 更新缓存时间,在C:\Users\username\.gnupg\gpg-agent.conf(如果文件不存在则创建文件),添加default-cache-ttl 34560000max-cache-ttl 34560000。这些时间以秒为单位,选择您想要的任何内容。
  3. 使用 重新启动 gpg-agent gpgconf --kill gpg-agent