Skip to content

DOC: Update policy to prefer squash merging #28821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions doc/devel/pr_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ unsure why a test is failing, ask on the PR or in our :ref:`communication-channe
Number of commits and squashing
-------------------------------

* Squashing is case-by-case. The balance is between burden on the
contributor, keeping a relatively clean history, and keeping a
history usable for bisecting. The only time we are really strict
about it is to eliminate binary files (ex multiple test image
re-generations) and to remove upstream merges.
* The default and preferred method of merging code into the main branch
is to squash merge commits so that a single clean and usable
commit is in the git history. The commit message should be cleaned up
by the person merging so that the git history has useful messages
when going through the history. If the commits are organized and contain
useful messages, the PR author can ask the person merging to not squash
the commits. This is done on a case-by-case basis and at the discretion
Comment on lines +235 to +237
Copy link
Member

@rcomer rcomer Sep 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the commits are organised and contain useful messages, does the author need to actively state they prefer their commits aren't squashed? It seems implied by the fact that they kept their commits in order. I think people who prefer that will mostly be our maintainers - who are a minority of contributors but account for a majority of PRs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always curious about this argument. Does anyone really care if the commits are "organized"? What do people do with that organization?

Copy link
Member

@timhoffm timhoffm Sep 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I care when trying to understand why code is written the way it is or since when. Using git blame gives you the commit that a line was changed. It's very helpful then if all related change is in the same commit and all unrelated change is not.

Answering @rcomer's question: Generally, if multiple commits look reasonable (*), we can keep them, no matter if the author stated that explicitly. This may very well happen for experienced non-core devs. They know how to structure compex topics over multiple commits, but may not be aware of our policies.

(*) Reasonable is to a certain extend in the eye of the beholder. One can easily identify the extremes. OTOH, I would not squash commits from other people if they are very clear. I would squash the "small" PRs with many trival commits. If I the PR is too large / touching multiple topics, and I have the feeling it should be split up, I'd ask the author to reorganize - this is likely even necessary for simpler review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure it's good to have reasonable commit histories. I'm just curious why folks would bother being overly meticulous with this. If a change is made in boo.py I'm not too likely to be confused by the blame if a change is also made in doc_boo.rst

But I'm fine if the merger wants to make a judgement call. I guess if in doubt ask. I think 99% of PRs a squash is fine and saves a step as noted in the original justification

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people just prefer that their own PRs are not squash-merged. I personally do quite like the fact that I can do

git branch --merged upstream/main

and it will tell me which of my branches can be safely deleted. That won't work any more if the branches are squash-merged. That said, this is just a preference, not a hill I'm going to die on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work any more if the branches are squash-merged.

Eek, that's the only way things get cleaned for me.

I think, like most maintainers, I just do my own rebase squash/plan to get to it after the final round of reviews. Or usually I've done something like tweak css/.toml/conf.py b/c of the PR but unrelated enough that I'll keep it in a separate commit for history/bisecting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for changing to squash-merge was so that we don't require more inexperienced authors to squash themselves. We could have a case-dependent policy: Stick with simple merge, but squash-merge if the PR commit(s) are not well organized. I think one can usually tell the difference (or ask if not). The downside is that we put the burden on reviewers and they have to select the strategy case-by-case - GitHub UI keeps the last used strategy as default and you'd have to go through the dropdown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the commits are organised and contain useful messages, does the author need to actively state they prefer their commits aren't squashed?

I think yes. I don't think it should be on the person merging to consider "oh this person wants X, this person wants Y".

The downside is that we put the burden on reviewers and they have to select the strategy case-by-case

I think that the bottom line of my thinking is that if someone chooses one method or the other, the author should not be upset about it. If someone wanted their commits kept, but they get squashed then 🤷 Make a small PR for each individual change instead with a single commit each which will guarantee those commits get kept separately.

Regarding removing local merged branches:

Rather than checking if a branch was merged, I check if a branch exists on my remote. So after someone merges, I click the "delete branch" button, which then deletes it from my origin. I then have an alias setup locally that I run every so often to prune these branches that don't exist on my origin.
https://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore I think this works as expected with squash merges as well because it is comparing branch names, but even if not, I'm sure there are ways I can adapt my local workflow for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping your local repo clean is an interesting use case of keeping commits the same. However after a merge I typically delete the branch on GitHub and then it's not on my "origin" remote. I treat my local repo as ephemeral.

of the person merging.

* Do not let perfect be the enemy of the good, particularly for
documentation or example PRs. If you find yourself making many
Expand Down