【问题标题】:How to configure and use `git send-email` to work with gmail to email patches to developers如何配置和使用 `git send-email` 与 gmail 一起使用电子邮件将补丁发送给开发人员
【发布时间】:2021-09-15 05:14:19
【问题描述】:

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


我想为glibc 做出贡献,例如,更新glibc/benchtests/bench-malloc-thread.c malloc 速度测试基准测试,但它们已经过时且过时,并且仍然生活在黑暗时代,我们必须通过电子邮件提交补丁:命令行而不是通过 GitHub 或 GitLab 打开拉取请求。 :)

在此处查看glibc 的投稿说明: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

【问题讨论】:

    标签: git


    【解决方案1】:

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

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

    在 Ubuntu 20.04 上测试。

    1. 安装git send-email:

      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. 将您的 Google 帐户配置为具有 1) 2 因素身份验证(启用应用专用密码)和 2) 用于 gmail 的 应用专用密码git send-email使用:

      1. 配置两步验证: 转到此处:https://myaccount.google.com/security --> 向下滚动到“两步验证”并按照流程将其打开。
      2. 为 gmail 生成一个特定于应用程序的密码以供 git 使用: 转到上面的链接,向下滚动到“应用程序密码”并单击它。选择“邮件”作为应用程序: 选择“其他(自定义名称)”作为设备:
        并将其命名为 git send-email 或类似名称。单击“生成”按钮。它将弹出一个 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 并按Enter 发送消息。当您第一次使用git send-email 发送电子邮件时,它会提示您输入密码。 使用您在上面为您的 Google 帐户生成的应用专用密码,电子邮件就会发送出去。

      由于您在上面的~/.gitconfig 文件中添加了[credential] helper = store 条目,git 现在会自动将您的应用程序专用密码存储在一个名为~/.git-credentials 的新文件中以供将来使用。如果您打开该文件,您将看到一个 URL 字符串,其中包含以纯文本形式嵌入的密码。它看起来像这样:

      smtp://EMAIL%40gmail.com:16-DIGIT-PASSWORD@smtp.gmail.com%3a587
      

      EMAIL 是您电子邮件地址的第一部分,在 @ 符号之前,16-DIGIT-PASSWORD 是您之前为您的 Google 帐户生成的 16 位应用专用密码,如上所述。

      希望您的硬盘驱动器已加密(您应该在首次安装 Ubuntu 时选择 LUKS 加密,用于全盘加密),并且您是计算机上唯一的 root 用户。如果是这种情况,这不是安全问题,因为ll ~/.git-credentials 显示-rw------- 1 your_username your_groupname,这意味着除了您之外的任何人都无法读取该文件。

    8. 完成!下次运行git send-email 时,您无需输入应用密码,因为它现在保存在~/.git-credentials 中。

    参考

    1. 查看问题底部的所有参考资料,以及我自己的大量研究和反复试验。

    【讨论】:

    • 感谢您将这一切放在一起。每条信息都可以在某个地方获得,但收集和测试显然是很多工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-19
    • 2019-10-18
    • 1970-01-01
    • 2016-05-21
    • 2016-01-30
    • 1970-01-01
    • 2014-02-16
    相关资源
    最近更新 更多