社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Gabriel Staples  »  全部回复
回复总数  2
5 年前
回复了 Gabriel Staples 创建的主题 » 如何配置并使用“git send email”与gmail一起向开发者发送补丁

如何配置和使用 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. 请参阅问题底部的所有参考资料,以及我自己的大量研究和尝试。

下面是如何使用“f字符串”和 range() 类中的对象 for

对于_loop_basic_演示。py:

#!/usr/bin/python3

END_NUM = 7
for i in range(1, END_NUM + 1):
    print(f"line{i}")

运行命令:

./for_loop_basic_demo.py

输出:

line1
line2
line3
line4
line5
line6
line7

更进一步:3种打印方式

我知道用Python打印格式化字符串的3种方法是:

  1. 格式化字符串文本;又名:“f弦”
  2. 这个 str.format() 方法,或
  3. C printf() -就像 % 操作人员

以下是三种技术的演示图片,为您展示每种技术:

#!/usr/bin/python3

END_NUM = 7
for i in range(1, END_NUM + 1):
    # 3 techniques to print:

    # 1. newest technique: formatted string literals; AKA: "f-strings"
    print(f"line{i}")

    # 2. newer technique: `str.format()` method
    print("line{}".format(i))

    # 3. oldest, C-like "printf"-style `%` operator print method
    # (sometimes is still the best method, however!)
    print("line%i" % i)

    print() # print just a newline char

运行cmd并输出:

eRCaGuy_hello_world/python$ ./for_loop_basic_demo.py 
line1
line1
line1

line2
line2
line2

line3
line3
line3

line4
line4
line4

line5
line5
line5

line6
line6
line6

line7
line7
line7

参考资料:

  1. *****这是一个 杰出的 阅读,我强烈建议你阅读并研究它!: Python String Formatting Best Practices
  2. 所有“内置函数”的官方Python文档。习惯于这样: https://docs.python.org/3/library/functions.html
    1. 这个 范围() 类,它创建了一个 range 对象,该对象允许 对于 循环迭代: https://docs.python.org/3/library/functions.html#func-range