Skip to content

Commit 2b99703

Browse files
authored
Add merge/squash guidelines to CONTRIBUTING.rst (#12672)
As discussed in #12633.
1 parent bc1e17e commit 2b99703

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

CONTRIBUTING.rst

+54-1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,57 @@ pull requests from other contributors yourself after having reviewed
380380
them.
381381

382382

383+
Merge/squash guidelines
384+
-----------------------
385+
386+
When a PR is approved and ready to be integrated to the ``main`` branch, one has the option to *merge* the commits unchanged, or *squash* all the commits into a single commit.
387+
388+
Here are some guidelines on how to proceed, based on examples of a single PR commit history:
389+
390+
1. Miscellaneous commits:
391+
392+
* ``Implement X``
393+
* ``Fix test_a``
394+
* ``Add myself to AUTHORS``
395+
* ``fixup! Fix test_a``
396+
* ``Update tests/test_integration.py``
397+
* ``Merge origin/main into PR branch``
398+
* ``Update tests/test_integration.py``
399+
400+
In this case, prefer to use the **Squash** merge strategy: the commit history is a bit messy (not in a derogatory way, often one just commits changes because they know the changes will eventually be squashed together), so squashing everything into a single commit is best. You must clean up the commit message, making sure it contains useful details.
401+
402+
2. Separate commits related to the same topic:
403+
404+
* ``Implement X``
405+
* ``Add myself to AUTHORS``
406+
* ``Update CHANGELOG for X``
407+
408+
In this case, prefer to use the **Squash** merge strategy: while the commit history is not "messy" as in the example above, the individual commits do not bring much value overall, specially when looking at the changes a few months/years down the line.
409+
410+
3. Separate commits, each with their own topic (refactorings, renames, etc), but still have a larger topic/purpose.
411+
412+
* ``Refactor class X in preparation for feature Y``
413+
* ``Remove unused method``
414+
* ``Implement feature Y``
415+
416+
In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, even if they serve a common topic overall. Looking at the history later, it is useful to have the removal of the unused method separately on its own commit, along with more information (such as how it became unused in the first place).
417+
418+
4. Separate commits, each with their own topic, but without a larger topic/purpose other than improve the code base (using more modern techniques, improve typing, removing clutter, etc).
419+
420+
* ``Improve internal names in X``
421+
* ``Add type annotations to Y``
422+
* ``Remove unnecessary dict access``
423+
* ``Remove unreachable code due to EOL Python``
424+
425+
In this case, prefer to use the **Merge** strategy: each commit is valuable on its own, and the information on each is valuable in the long term.
426+
427+
428+
As mentioned, those are overall guidelines, not rules cast in stone. This topic was discussed in `#12633 <https://github.com/pytest-dev/pytest/discussions/12633>`_.
429+
430+
431+
*Backport PRs* (as those created automatically from a ``backport`` label) should always be **squashed**, as they preserve the original PR author.
432+
433+
383434
Backporting bug fixes for the next patch release
384435
------------------------------------------------
385436

@@ -438,6 +489,8 @@ above?
438489
All the above are not rules, but merely some guidelines/suggestions on what we should expect
439490
about backports.
440491

492+
Backports should be **squashed** (rather than **merged**), as doing so preserves the original PR author correctly.
493+
441494
Handling stale issues/PRs
442495
-------------------------
443496

@@ -485,7 +538,7 @@ When closing a Pull Request, it needs to be acknowledging the time, effort, and
485538

486539
<bye>
487540

488-
Closing Issues
541+
Closing issues
489542
--------------
490543

491544
When a pull request is submitted to fix an issue, add text like ``closes #XYZW`` to the PR description and/or commits (where ``XYZW`` is the issue number). See the `GitHub docs <https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>`_ for more information.

0 commit comments

Comments
 (0)