Py学习  »  Git

如何配置并使用“git send email”与gmail一起向开发者发送补丁

Gabriel Staples • 4 年前 • 2183 次点击  

如何配置 git send-email 使用gmail?


我想为你做贡献 glibc ,例如,更新 glibc/benchtests/bench-malloc-thread.c malloc speed test benchtest,但它们既古老又过时,仍然生活在黑暗时代,我们必须通过命令行的电子邮件提交补丁,而不是通过GitHub或GitLab打开拉取请求。:)

看见 格利伯 以下是作者的投稿说明: https://sourceware.org/glibc/wiki/Contribution%20checklist :

  • 使用创建一个或多个修补程序 git format-patch
  • 使用 git send-email --to=libc-alpha@sourceware.org 要将修补程序发送到列表,请使用 --cc 如果需要,引起特定维护人员的注意。
  • 如果你的补丁还没有被审核,至少每周Ping一次

我试着阅读并遵循一些参考资料,但似乎没有一个是完整的,即:

  1. git: 'send-email' is not a git command. See 'git --help'
  2. https://coderwall.com/p/qcsiew/setting-up-and-using-git-send-email-with-gmail
  3. https://coderwall.com/p/dp-gka/setting-up-git-send-email-with-gmail
  4. https://git-scm.com/docs/git-send-email#_use_gmail_as_the_smtp_server
  5. https://git-scm.com/docs/git-credential
  6. https://gist.github.com/jasonkarns/4354421
  7. https://gist.github.com/winksaville/dd69a860d0d05298d1945ceff048ce46
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129616
文章 [ 1 ]  |  最新文章 4 年前
Gabriel Staples
Reply   •   1 楼
Gabriel Staples    5 年前

如何配置和使用 git send-email 用gmail

经过大量的努力,并使用问题底部的所有资源,我能够从所有来源的组合中拼凑出一个解决方案。请容忍我。

在Ubuntu 20.04上测试。

  1. 安装 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'.
    
  2. 安装Perl脚本依赖项(必须已安装Perl):

    cpan Authen::SASL MIME::Base64 Net::SMTP::SSL
    

    资料来源: https://coderwall.com/p/qcsiew/setting-up-and-using-git-send-email-with-gmail

  3. 配置您的 ~/.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

  4. 将你的谷歌账号配置为1) 双因素认证 (启用特定于应用程序的密码)和2) 应用程序特定密码 供gmail用户使用 git发送电子邮件 :

    1. 配置双因素身份验证: 到这里: https://myaccount.google.com/security -->向下滚动至“两步验证”,然后按照流程将其打开。
    2. 为git使用的gmail生成特定于应用程序的密码: 转到上面的链接,向下滚动至“应用程序密码”,然后单击它。选择“邮件”作为应用程序: enter image description here 选择“其他” (自定义名称) “作为设备: enter image description here
      说出它的名字 git发送电子邮件 ,或类似的。点击“生成”按钮。它会弹出一个16位的完全访问密码。写下来,不要留空格。这只是16个字符。
  5. 如果需要的话,把你想通过电子邮件发送的提交压缩成一个补丁。有多种壁球技术,但这里有一种常见的方法:

    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.
    
  6. 为最新的压缩提交创建修补程序文件:

    git format-patch -1 HEAD
    

    这将生成一个补丁文件。例子: 0001-bench-malloc-thread.c-add-assert-that-malloc-is-neve.patch .

  7. 通过电子邮件将补丁文件发送到需要的位置。对于初始测试,我们只需通过电子邮件发送给您自己 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 ,这意味着除了您之外,其他人都无法读取该文件。

  8. 完成!下次你跑步的时候 git发送电子邮件 ,您将不必输入应用程序密码,因为它现在保存在 ~/.git凭据 .

工具书类

  1. 请参阅问题底部的所有参考资料,以及我自己的大量研究和尝试。