|
|
•
1 楼
Gabriel Staples
5 年前
如何配置和使用
git send-email
用gmail
经过大量的努力,并使用问题底部的所有资源,我能够从所有来源的组合中拼凑出一个解决方案。请容忍我。
在Ubuntu 20.04上测试。
-
安装
git发送电子邮件
:
sudo apt update
sudo apt install git-email
资料来源:
git: 'send-email' is not a git command. See 'git --help'
如果没有上述安装,您将看到:
git: 'send-email' is not a git command. See 'git --help'.
-
安装Perl脚本依赖项(必须已安装Perl):
cpan Authen::SASL MIME::Base64 Net::SMTP::SSL
资料来源:
https://coderwall.com/p/qcsiew/setting-up-and-using-git-send-email-with-gmail
-
配置您的
~/.gitconfig
通过确保文件中包含以下内容来归档:
[user]
name = First Last
email = my_email@gmail.com
[sendemail]
smtpServer = smtp.gmail.com
smtpServerPort = 587
smtpEncryption = tls
smtpUser = my_email@gmail.com
# (Optional: we'll leave this commented out and use a different way)
# smtpPass = PASSWORD
[credential]
helper = store
资料来源:各种各样的地方,但唯一一个说要添加
[credential]
部分(非常重要)是:
https://gist.github.com/winksaville/dd69a860d0d05298d1945ceff048ce46
-
将你的谷歌账号配置为1)
双因素认证
(启用特定于应用程序的密码)和2)
应用程序特定密码
供gmail用户使用
git发送电子邮件
:
-
配置双因素身份验证:
到这里:
https://myaccount.google.com/security
-->向下滚动至“两步验证”,然后按照流程将其打开。
-
为git使用的gmail生成特定于应用程序的密码:
转到上面的链接,向下滚动至“应用程序密码”,然后单击它。选择“邮件”作为应用程序:
选择“其他”
(自定义名称)
“作为设备:
说出它的名字
git发送电子邮件
,或类似的。点击“生成”按钮。它会弹出一个16位的完全访问密码。写下来,不要留空格。这只是16个字符。
-
如果需要的话,把你想通过电子邮件发送的提交压缩成一个补丁。有多种壁球技术,但这里有一种常见的方法:
git rebase -i my_first_commit~ # do NOT forget the tilde (~) at the end!
# In the git editor that opens up, manually set the first entry to
# "pick", and set all others afterwards to "squash", or just "s" for short.
# Save, then close the editor and let it squash.
-
为最新的压缩提交创建修补程序文件:
git format-patch -1 HEAD
这将生成一个补丁文件。例子:
0001-bench-malloc-thread.c-add-assert-that-malloc-is-neve.patch
.
-
通过电子邮件将补丁文件发送到需要的位置。对于初始测试,我们只需通过电子邮件发送给您自己
my_email@gmail.com
.
git send-email --to=my_email@gmail.com 0001-bench-malloc-thread.c-add-assert-that-malloc-is-neve.patch
将显示有关电子邮件的信息,然后在结尾处显示:
Send this email? ([y]es|[n]o|[e]dit|[q]uit|[a]ll):
类型
y
和媒体
进来
发送信息。您第一次使用电子邮件发送电子邮件
git发送电子邮件
它会提示输入密码。
使用你为上面的谷歌账户生成的特定于应用程序的密码,
电子邮件将发送。
自从你添加了
[credential] helper = store
进入你的
~/.gitconfig
在上面的文件中,git现在会自动将你的应用程序特定密码存储在一个名为
~/.git-credentials
。如果打开该文件,您将看到一个URL字符串,其中以明文形式嵌入了您的密码。它看起来是这样的:
smtp://EMAIL%40gmail.com:16-DIGIT-PASSWORD@smtp.gmail.com%3a587
哪里
EMAIL
是您电子邮件地址的第一部分,在
@
签名,然后
16-DIGIT-PASSWORD
是您之前为您的谷歌账户生成的16位特定于应用程序的密码,如上所示。
希望你的硬盘是加密的(当你第一次安装Ubuntu时,你应该选择LUKS encryption,进行完整的磁盘加密),并且你是计算机上唯一的root用户。如果是这样的话,这不是安全问题,因为
ll ~/.git-credentials
显示
-rw------- 1 your_username your_groupname
,这意味着除了您之外,其他人都无法读取该文件。
-
完成!下次你跑步的时候
git发送电子邮件
,您将不必输入应用程序密码,因为它现在保存在
~/.git凭据
.
工具书类
-
请参阅问题底部的所有参考资料,以及我自己的大量研究和尝试。
|