Android Studio和Git - 如何通过GPG签署我的提交?

问题描述 投票:21回答:3

根据this link,我只需要使用我的GPG密钥包含-S开关来签署我的提交,但我不知道如何在Android Studio中使用它。

如何在Android Studio中签署我的提交?

编辑:我很欣赏OSX解决方案的出现,但我真的希望看到一个适用于Windows的答案。我只使用我的Mac作为文档和东西。

windows git android-studio github gnupg
3个回答
5
投票

进行一些测试后我按照这个步骤进行操作请按照以下步骤重新启动Android Studio:

你是否厌倦了为每次提交写密码?

nano~ / .gnupg / gpg.conf

add the following lines

use-agent
no-tty
default-key <your key id>
  • 完成所有配置后,如果您使用MacOS。你应该:

ln -s /usr/local/Cellar/libgcrypt/1.7.0_1 / usr / local / opt / libgcrypt

ln -s /usr/local/Cellar/libgpg-error/1.22 / usr / local / opt / libgpg-error

ln -s /usr/local/Cellar/libassuan/2.4.2 / usr / local / opt / libassuan

ln -s /usr/local/Cellar/pth/2.0.7 / usr / local / opt / pth

  • 执行

来源〜/ .profile

  • 使用选项-S进行一次提交

git commit -am“我的提交消息”-S

  • 你应该得到一个密码提示。 - 把你的密码

而已!!!


5
投票

正如我在“Sign git commits with GPG”中提到的,使用Git 2.0:

如果要对所有提交进行GPG签名,则必须始终添加-S选项。 commit.gpgsign配置选项允许自动签署所有提交。

这不完全有效,并且是followed by issue 127802,具有以下变通方法:

使用该内容创建了一个帮助脚本:

/usr/bin/gpg –batch –no-tty "$@"

并将gpg.program设置为该脚本

要么:

将“no-tty”添加到“~/.gnupg/gpg.conf”为我解决了这个问题。

您可能仍会收到错误消息:

Commit failed with error:
gpg: problem with the agent - disabling agent use
gpg: Sorry, no terminal at all requested - can't get input
error: gpg failed to sign the data
fatal: failed to write commit object

再次:bug正在进行中,其次是issue 110261

除了之前的解决方案(OS X)之外,还要解决此问题:

1)brew install gnupg gnupg2 pinentry-mac

2)nano ~/.gnupg/gpg-agent.conf - > pinentry-program /usr/local/bin/pinentry-mac

3)git config -–global gpg.program gpg2


1
投票

如果您安装了适用于Windows的git,并在安装过程中选择了MingGW选项,那么这就是我使用Android Studio处理签名提交的过程。

提供/使用的程序,用于那些尚未拥有它们的人。

对于那些想要阅读文章的人,我曾经在我的Windows环境中使用gpg签名工作(从git config行开始的页面的下半部分是我们更关心的):https://jamesmckay.net/2016/02/signing-git-commits-with-gpg-on-windows/

我将简要介绍一下通过命令行执行gpg部分的过程 - 假设所有三个程序都是从这里开始安装的。

Check Git setting in Android Studio

如果您尚未在Android Studio中指定git的位置,请在“设置”中执行以下操作:

注意:这可以在一个项目的File > Project SettingsFile > Other Settings > Default Settings...中完成

版本控制> Git> Git可执行文件的路径

由于我使用的是MinGW版本,因此设置为:C:\Program Files\Git\mingw64\bin\git.exe

Export existing public and secret keys from MinGW version (git bash)

注意:使用MinGW提示程序执行

  1. gpg --export > ~/gpg-public
  2. gpg --export-secret-keys > ~/gpg-secret

注意:对于那些不知道的人,~/默认设置为用户的主目录。 (例如Windows 10:C:/Users/%USERNAME%

Import exported keys into Gpg4win

注意:使用Windows命令提示符执行。

  1. gpg --import < "C:/Users/%USERNAME%/gpg-public"
  2. gpg --import < "C:/Users/%USERNAME%/gpg-secret"

将地址替换为gpg-publicgpg-secret文件的位置。

Make git use gpg from Gpg4win

正如文章中提到的那样。如果你没有打开它,它会在这里重新发布。

注意:使用MinGW提示程序执行

  • git config --global gpg.program "C:/Program Files (x86)/GNU/GnuPG/gpg2.exe"

gpg.program值(保持gpg2.exe)替换为您指定gpg4win安装程序以安装它的位置。

(可选)当您使用它时,您可以配置您的git以使用默认密钥自动签署您的提交(需要git version> = 2.0)

  • git config --global user.name <name>
  • git config --global user.email <email>
  • git config --global user.signingkey <your-key-ID>
  • git config --global commit.gpgsign true

用您自己的值替换< >中的值。您可以通过运行gpg --list-keys并从pub开始并在/之后的行中获取ID来获取密钥ID。

现在您应该能够使用Android Studio提交并看到密码输入的提示。

© www.soinside.com 2019 - 2024. All rights reserved.