如何使用git send-email

How to Use git send-email

建议使用git send-email发送补丁(更多关于发送补丁的信息请参考Community ). 本文介绍如何使用git send-email.

安装 send-email

你的git可能已经安装了,但是send-email命令不是git必需的组件。你可以使用“git send-email --help” 确认一下。如果显示send-email的man page,那么send-email已经安装再你的系统了。否则,你需要安装send-email命令。你的版本可能有一个send-email的安装包。在Debian下,这个安装包的名字是"git-email" 。

配置你的名字和Email地址

你应该告诉git你的名字和email地址。你可能已经做了这一步了,如果没有,执行下面的命令:

git config --global user.name "My Name"
git config --global user.email "myemail@example.com"

配置Mail发送选项

git send-email 发送emails通过你的SMTP 服务器, 所以你需要配置服务器参数。参考你的email提供商的文档找到正确的参数。下面是我的mail设置:

git config --global sendemail.smtpencryption tls
git config --global sendemail.smtpserver mail.messagingengine.com
git config --global sendemail.smtpuser tanuk@fastmail.fm
git config --global sendemail.smtpserverport 587
git config --global sendemail.smtppass hackme

Storing the password in the git configuration file is obviously a security risk. It's not mandatory to configure the password. If it's not configured, git send-email will ask it every time the command is used.

配置默认的目的地址

For PulseAudio, the patches should be sent to our mailing list. In order to avoid having to remember it and retyping it all the time, you can configure the address to be used by default by git send-email. As you may contribute to many projects using git, it does not make sense to set this option globally so instead we'll only set it in our clone of the PulseAudio code.

git config sendemail.to pulseaudio-discuss@lists.freedesktop.org

避免发送邮件给你自己

默认情况下,git send-email会把作者添加到Cc:field. 当你发送你自己写的patches, 这意味着每个patch的拷贝都会发送到你自己的邮箱. 如果你不喜欢这样, 你可以通过设置下面的选项来避免这种情况(see "git send-email --help" for the full list of possible values):

git config --global sendemail.suppresscc self

使用send-email命令

See "git send-email --help" for the full reference. I'll go through only the basic usage here.

git send-email will ask a few questions before the patches are sent (update: newer git versions ask fewer questions, sometimes no questions at all). Most of the questions have a sensible default value shown in square brackets. Just press enter to use the default value. Type the answer to the question if you don't want to use the default answer. The questions are:

  • Who should the emails appear to be from?
    • This will be used as the "From" header. You should have configured your name and email address earlier, so the default is usually correct.
  • Who should the emails be sent to?
  • Message-ID to be used as In-Reply-To for the first email?
    • This should usually be left empty. Don't send patches as replies to regular discussion, that makes it harder to keep track of the patches.
  • Send this email?
    • The mail headers are visible above the question, so that you can check that everything looks OK.

发送一个单独的Patch

在当前的分支发送最新的commit:

git send-email -1

发送其他的commit:

git send-email -1 <commit reference>

发送多个Patches

Sending the last 10 commits in the current branch:

git send-email -10 --cover-letter --annotate

The --cover-letter option creates an extra mail that will be sent before the actual patch mails. You can add write some introduction to the patch set in the cover letter. If you need to explain the patches, be sure to include the explanations also in the commit messages, because the cover letter text won't be recorded in the git history. If you don't think any introduction or explanation is necessary, it's fine to only have the shortlog that is included in the cover letter by default, and only set the "Subject" header to something sensible.

The --annotate option causes an editor to be started for each of the mails, allowing you to edit the mails. The option is always necessary, so that you can edit the cover letter's "Subject" header.

添加Patch版本信息

By default the patch mails will have "[PATCH]" in the subject (or "[PATCH n/m]", where n is the sequence number of the patch and m is the total number of patches in the patch set). When sending updated versions of patches, the version should be indicated: "[PATCH v2]" or "[PATCH v2 n/m]". To do this, use the --annotate option and edit the "Subject" header of the mails.

添加额外的注释到Patch Mails

Sometimes it's convenient to annotate patches with some notes that are not meant to be included in the commit message. For example, one might want to write "I'm not sure if this should be committed yet, because..." in a patch, but the text doesn't make sense in the commit message. Such messages can be written below the three dashes "---" that are in every patch after the commit message. Use the --annotate option with git send-email to be able to edit the mails before they are sent.


原文http://www.freedesktop.org/wiki/Software/PulseAudio/HowToUseGitSendEmail/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值