|
| 1 | +.. _backporting: |
| 2 | +.. _branch-merge: |
| 3 | + |
| 4 | +Backporting merged changes |
| 5 | +========================== |
| 6 | + |
| 7 | +After a pull request has been merged into ``main``, it may need to be backported |
| 8 | +to one or more :ref:`maintenance <maintbranch>` or :ref:`security <secbranch>` |
| 9 | +branches. The project's backport policy is described in the |
| 10 | +:ref:`development cycle guide <maintbranch>`. |
| 11 | + |
| 12 | +The :samp:`needs backport to {X.Y}` labels on a pull request indicate which |
| 13 | +versions should receive a backport. ``miss-islington`` will automatically |
| 14 | +attempt to create backport pull requests for the versions indicated by these |
| 15 | +labels. If it cannot create a backport pull request because of conflicts, use |
| 16 | +the :pypi:`cherry-picker` tool to create the backport and resolve the conflicts |
| 17 | +manually. |
| 18 | + |
| 19 | +You need the commit hash of the squashed commit that was merged into ``main``. |
| 20 | +``miss-islington`` should post a comment when it is unable to create the |
| 21 | +backport automatically, including the full command and commit hash. If that |
| 22 | +comment is not posted, look for an event on the merged pull request similar to: |
| 23 | + |
| 24 | +.. code-block:: text |
| 25 | +
|
| 26 | + <core_developer> merged commit <commit_sha1> into python:main <sometime> ago. |
| 27 | +
|
| 28 | +By following the link to ``<commit_sha1>``, you can get the full commit hash. |
| 29 | + |
| 30 | +Alternatively, you can obtain the commit hash with these Git commands:: |
| 31 | + |
| 32 | + $ git fetch upstream |
| 33 | + $ git rev-parse ":/gh-<PR number>" |
| 34 | + |
| 35 | +These commands print the hash of the commit whose message contains |
| 36 | +``gh-<PR number>``. |
| 37 | + |
| 38 | +Use the commit hash and the :pypi:`cherry-picker` tool to create the backport. |
| 39 | +In the following command, ``<branch>`` is the target maintenance branch (for |
| 40 | +example, ``3.12``): |
| 41 | + |
| 42 | +.. code-block:: text |
| 43 | +
|
| 44 | + $ cherry_picker <commit_sha1> <branch> |
| 45 | +
|
| 46 | +Follow the instructions provided. You may need to identify files with |
| 47 | +conflicts, fix them, and build and run applicable tests. When you are finished, |
| 48 | +stage all modified files and run ``cherry_picker --continue`` to push the |
| 49 | +backport. |
| 50 | + |
| 51 | +The tool usually generates the commit message automatically. If it does not, |
| 52 | +keep the original commit message unchanged, except for removing the backport |
| 53 | +pull request number (``(#XXXXX)``), and append a |
| 54 | +``(cherry picked from commit <commit_sha1>)`` line. |
| 55 | + |
| 56 | +The format of a correct backport commit message is: |
| 57 | + |
| 58 | +.. code-block:: text |
| 59 | + :class: good |
| 60 | +
|
| 61 | + [<branch>] gh-XXXXX: <original commit title> (GH-XXXXX) |
| 62 | +
|
| 63 | + <original commit body> |
| 64 | +
|
| 65 | + (cherry picked from commit <commit_sha1>) |
| 66 | +
|
| 67 | +Here ``gh-XXXXX`` is the GitHub *issue* number, and ``(GH-XXXXX)`` is the |
| 68 | +original *pull request* number. |
| 69 | + |
| 70 | +An example of a bad backport commit message: |
| 71 | + |
| 72 | +.. code-block:: text |
| 73 | + :class: bad |
| 74 | +
|
| 75 | + gh-XXXXX: Custom title (GH-XXXXX) (#XXXXX) |
| 76 | +
|
| 77 | + * Custom message |
| 78 | +
|
| 79 | +When opening the backport pull request, its title must follow the same format |
| 80 | +as the commit title, beginning with the ``[<branch>]`` prefix and referencing |
| 81 | +the original pull request with a ``(GH-XXXXX)`` suffix. For example: |
| 82 | + |
| 83 | +.. code-block:: text |
| 84 | + :class: good |
| 85 | +
|
| 86 | + [3.15] gh-12345: Fix the spam module (GH-24680) |
| 87 | +
|
| 88 | +After the backport pull request is opened, ``miss-islington`` will link it to |
| 89 | +the original pull request and remove the corresponding backport label. |
0 commit comments