Skip to content

Commit cfd01cf

Browse files
Revise the "Backporting merged changes" guide (GH-1819)
1 parent 856b971 commit cfd01cf

2 files changed

Lines changed: 49 additions & 60 deletions

File tree

core-team/committing.rst

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -149,44 +149,10 @@ bug fixes or security fixes. In almost all cases the fixes should first
149149
originate on ``main`` and then be ported back to older branches.
150150

151151

152-
.. _branch-merge:
153-
154152
Backporting changes to an older version
155153
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156154

157-
If it is determined that a pull request needs to be backported into one or
158-
more of the maintenance branches, then a core team member can apply the label
159-
``needs backport to X.Y`` to the pull request.
160-
161-
After the pull request has been merged, miss-islington (bot) will first try to
162-
do the backport automatically. If miss-islington is unable to do it,
163-
then the pull request author or the core team member who merged it should look into
164-
backporting it themselves, using the backport generated by cherry_picker.py_
165-
as a starting point.
166-
167-
You can get the commit hash from the original pull request, or you can use
168-
``git log`` on the ``main`` branch. To display the 10 most recent commit
169-
hashes and their first line of the commit, use the following command::
170-
171-
git log -10 --oneline
172-
173-
.. _backport-pr-title:
174-
175-
You can prefix the backport pull request with the branch, and reference
176-
the pull request number from ``main``. Here is an example::
177-
178-
[3.9] gh-12345: Fix the Spam Module (GH-NNNN)
179-
180-
Here "gh-12345" is the GitHub *issue* number, and "GH-NNNN" is the
181-
number of the original *pull request*.
182-
Note that cherry_picker.py_ adds the branch prefix automatically.
183-
184-
Once the backport pull request has been created, remove the
185-
``needs backport to X.Y`` label from the original pull request. (Only
186-
members of the core team and :ref:`Python Triage Team <triage-team>`
187-
can apply labels to GitHub pull requests).
188-
189-
.. _cherry_picker.py: https://github.com/python/cherry-picker
155+
This section has moved to :ref:`branch-merge`.
190156

191157

192158
Reverting a merged pull request

getting-started/git-boot-camp.rst

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -557,60 +557,83 @@ dismissing your previous review that requested changes.
557557
Note that pushing new changes after the auto-merge flow was enabled
558558
does **NOT** stop it.
559559

560+
561+
.. _branch-merge:
562+
560563
Backporting merged changes
561564
--------------------------
562565

563-
A pull request may need to be backported into one of the maintenance branches
564-
after it has been accepted and merged into ``main``. It is usually indicated
565-
by the label ``needs backport to X.Y`` on the pull request itself.
566+
After a pull request has been merged into ``main``, it may need to be backported
567+
to one or more :ref:`maintenance <maintbranch>` or :ref:`security <secbranch>`
568+
branches. This is indicated by the :samp:`needs backport to {X.Y}` labels on
569+
the pull request.
566570

567-
Use the utility script
568-
`cherry_picker.py <https://github.com/python/cherry-picker>`__
569-
to backport the commit.
571+
``miss-islington`` will automatically attempt to create backport PRs for the
572+
versions indicated by these labels. If ``miss-islington`` cannot create a
573+
backport PR due to conflicts, you can use the :pypi:`cherry-picker` tool to
574+
create the backport and resolve the conflicts manually.
570575

571-
The commit hash for backporting is the squashed commit that was merged to
572-
the ``main`` branch. On the merged pull request, scroll to the bottom of the
573-
page. Find the event that says something like:
576+
You need the commit hash of the squashed commit that was merged into
577+
the ``main`` branch. ``miss-islington`` should post a comment when it is unable
578+
to create the backport automatically, including the full command and commit hash.
579+
If that comment is not posted, look for an event on the merged
580+
pull request similar to:
574581

575582
.. code-block:: text
576583
577584
<core_developer> merged commit <commit_sha1> into python:main <sometime> ago.
578585
579-
By following the link to ``<commit_sha1>``, you will get the full commit hash.
586+
By following the link to ``<commit_sha1>``, you can get the full commit hash.
580587

581-
Alternatively, the commit hash can also be obtained by the following Git
588+
Alternatively, the commit hash can also be obtained with the following Git
582589
commands::
583590

584591
$ git fetch upstream
585-
$ git rev-parse ":/gh-12345"
592+
$ git rev-parse ":/gh-<PR number>"
593+
594+
These commands print the hash of the commit whose message contains ``gh-<PR number>``.
586595

587-
The above commands will print out the hash of the commit containing
588-
``"gh-12345"`` as part of the commit message.
596+
You can then use the commit hash and the :pypi:`cherry-picker` tool to create
597+
the backport. In the following command, ``<branch>`` is the target maintenance
598+
branch (for example, ``3.12``):
599+
600+
.. code-block:: text
589601
590-
When formatting the commit message for a backport commit: leave the original
591-
one as is and delete the number of the backport pull request.
602+
$ cherry_picker <commit_sha1> <branch>
592603
593-
✅ Example of good backport commit message:
604+
Then, follow the instructions provided. You will have to identify the files
605+
with conflicts, fix them, and build and run applicable tests if necessary.
606+
When you are finished, ``git add`` all modified files and run
607+
``cherry_picker --continue`` to push the backport.
608+
609+
The tool usually generates the commit message automatically. If it does not, use
610+
the following format: Keep the original commit message unchanged, except for
611+
removing the backport pull request number (``(#XXXXX)``). At the end of the
612+
message, append a ``(cherry picked from commit <commit_sha1>)`` line.
613+
614+
The format of a correct backport commit message is:
594615

595616
.. code-block:: text
596617
:class: good
597618
598-
gh-12345: Improve the spam module (GH-777)
619+
[<branch>] gh-XXXXX: <original commit title> (GH-XXXXX)
599620
600-
* Add method A to the spam module
601-
* Update the documentation of the spam module
621+
<original commit body>
602622
603-
(cherry picked from commit 62adc55)
623+
(cherry picked from commit <commit_sha1>)
604624
605-
❌ Example of bad backport commit message:
625+
An example of a bad backport commit message:
606626

607627
.. code-block:: text
608628
:class: bad
609629
610-
gh-12345: Improve the spam module (GH-777) (#888)
630+
gh-XXXXX: Custom title (GH-XXXXX) (#XXXXX)
631+
632+
* Custom message
633+
634+
After the backport PR is opened, ``miss-islington`` will link it to the original
635+
PR and remove the corresponding backport label.
611636

612-
* Add method A to the spam module
613-
* Update the documentation of the spam module
614637

615638
Editing a pull request prior to merging
616639
---------------------------------------

0 commit comments

Comments
 (0)