创建拉取请求¶
本章描述了维护者如何创建和向其他维护者提交拉取请求。这对于将更改从一个维护者的树转移到另一个维护者的树很有用。
本文档由 Tobin C. Harding(当时他不是一个有经验的维护者)主要根据 Greg Kroah-Hartman 和 Linus Torvalds 在 LKML 上的评论编写。Jonathan Corbet 和 Mauro Carvalho Chehab 提出了建议和修复。误述是无意的,但不可避免,请将指责指向 Tobin C. Harding <me@tobin.cc>。
原始邮件线程
https://lore.kernel.org/r/[email protected]
创建分支¶
首先,您需要在单独的分支上包含您希望包含在拉取请求中的所有更改。通常,您将基于您打算向其发送拉取请求的开发人员树中的分支创建此分支。
为了创建拉取请求,您必须首先标记您刚刚创建的分支。建议您选择一个有意义的标签名称,以便您和其他人即使在一段时间后也能理解。一个好的做法是在名称中包含来源子系统和目标内核版本的指示。
Greg 提供了以下示例。对于驱动程序/char 的杂项内容,要在内核版本 4.15-rc1 中应用的拉取请求可以命名为 char-misc-4.15-rc1
。如果这样的标签是从名为 char-misc-next
的分支生成的,您将使用以下命令
git tag -s char-misc-4.15-rc1 char-misc-next
这将创建一个名为 char-misc-4.15-rc1
的签名标签,该标签基于 char-misc-next
分支中的最后一个提交,并使用您的 gpg 密钥对其进行签名(请参阅配置 Git)。
Linus 只接受基于签名标签的拉取请求。其他维护者可能会有所不同。
当您运行上述命令 git
时,它会将您带入编辑器,并要求您描述该标签。在这种情况下,您正在描述一个拉取请求,因此请概述其中包含的内容,为什么要合并它,以及是否已完成任何测试。所有这些信息都将最终出现在标签本身中,然后在维护者合并拉取请求时所做的合并提交中。因此,请将其写好,因为它将永远保留在内核树中。
正如 Linus 所说
Anyway, at least to me, the important part is the *message*. I want
to understand what I'm pulling, and why I should pull it. I also
want to use that message as the message for the merge, so it should
not just make sense to me, but make sense as a historical record
too.
Note that if there is something odd about the pull request, that
should very much be in the explanation. If you're touching files
that you don't maintain, explain _why_. I will see it in the
diffstat anyway, and if you didn't mention it, I'll just be extra
suspicious. And when you send me new stuff after the merge window
(or even bug-fixes, but ones that look scary), explain not just
what they do and why they do it, but explain the _timing_. What
happened that this didn't go through the merge window..
I will take both what you write in the email pull request _and_ in
the signed tag, so depending on your workflow, you can either
describe your work in the signed tag (which will also automatically
make it into the pull request email), or you can make the signed
tag just a placeholder with nothing interesting in it, and describe
the work later when you actually send me the pull request.
And yes, I will edit the message. Partly because I tend to do just
trivial formatting (the whole indentation and quoting etc), but
partly because part of the message may make sense for me at pull
time (describing the conflicts and your personal issues for sending
it right now), but may not make sense in the context of a merge
commit message, so I will try to make it all make sense. I will
also fix any speeling mistaeks and bad grammar I notice,
particularly for non-native speakers (but also for native ones
;^). But I may miss some, or even add some.
Linus
Greg 给出了一个拉取请求的示例
Char/Misc patches for 4.15-rc1
Here is the big char/misc patch set for the 4.15-rc1 merge window.
Contained in here is the normal set of new functions added to all
of these crazy drivers, as well as the following brand new
subsystems:
- time_travel_controller: Finally a set of drivers for the
latest time travel bus architecture that provides i/o to
the CPU before it asked for it, allowing uninterrupted
processing
- relativity_shifters: due to the affect that the
time_travel_controllers have on the overall system, there
was a need for a new set of relativity shifter drivers to
accommodate the newly formed black holes that would
threaten to suck CPUs into them. This subsystem handles
this in a way to successfully neutralize the problems.
There is a Kconfig option to force these to be enabled
when needed, so problems should not occur.
All of these patches have been successfully tested in the latest
linux-next releases, and the original problems that it found have
all been resolved (apologies to anyone living near Canberra for the
lack of the Kconfig options in the earlier versions of the
linux-next tree creations.)
Signed-off-by: Your-name-here <your_email@domain>
标签消息格式就像 git 提交 id。顶部有一行“摘要主题”,并确保在底部签名。
现在您有了本地签名标签,您需要将其推送到可以检索到的位置
git push origin char-misc-4.15-rc1
创建拉取请求¶
最后要做的事情是创建拉取请求消息。git
可以使用 git request-pull
命令为您方便地完成此操作,但它需要一些帮助来确定您要拉取的内容以及要基于什么进行拉取(以显示要拉取的正确更改和差异统计)。以下命令将生成拉取请求
git request-pull master git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git/ char-misc-4.15-rc1
引用 Greg
This is asking git to compare the difference from the
'char-misc-4.15-rc1' tag location, to the head of the 'master'
branch (which in my case points to the last location in Linus's
tree that I diverged from, usually a -rc release) and to use the
git:// protocol to pull from. If you wish to use https://, that
can be used here instead as well (but note that some people behind
firewalls will have problems with https git pulls).
If the char-misc-4.15-rc1 tag is not present in the repo that I am
asking to be pulled from, git will complain saying it is not there,
a handy way to remember to actually push it to a public location.
The output of 'git request-pull' will contain the location of the
git tree and specific tag to pull from, and the full text
description of that tag (which is why you need to provide good
information in that tag). It will also create a diffstat of the
pull request, and a shortlog of the individual commits that the
pull request will provide.
Linus 回应说他倾向于使用 git://
协议。其他维护者可能偏好不同。另请注意,如果您在没有签名标签的情况下创建拉取请求,那么 https://
可能是更好的选择。请参阅原始线程了解完整讨论。
提交拉取请求¶
拉取请求的提交方式与普通补丁相同。以内联电子邮件的形式发送给维护者,并根据需要抄送 LKML 和任何子系统特定的列表。发送给 Linus 的拉取请求通常具有如下主题行
[GIT PULL] <subsystem> changes for v4.15-rc1