News for hackers. Stuff that matters.
Re:Why large companies and fast-moving startups are banning ... by imiric on Friday December 29, 2023 @04:16PM (#38810295)
There are many reasons for having several commits in the same PR.

PRs often have a lot of overhead. They need a separate branch, CI jobs need to run, there are more notifications for everyone, separate approvals, etc.

Sometimes there's a need for keeping separate commits if they're all related to a single change. Proposing them all as part of the same PR helps maintaining that context while reviewing as well. Reviewers can always choose to focus on individual commits, and see the progression easily.

Sometimes it does makes sense to squash a PR if the work is part of the same change, but the golden rule of atomic commits always applies. Never just blindly squash PRs.

In fact, if the PR is messy and contains fixes and changes from the review, and the PR should have more than one commit, I go back and clean up the history by squashing each change to its appropriate commit. `git commit --fixup` helps with this, so I also prefer addressing comments locally rather than via GitHub's UI. Then it's a simple matter of running `git rebase --autosquash`.

Re:Why large companies and fast-moving startups are banning ... by burntsushi on Friday December 29, 2023 @04:30PM (#38810431)
I do the same. Given that you didn't mention git-absorb[1], I wonder if you've tried it. If not, you might be very happy to discover it.

[1]: https://github.com/tummychow/git-absorb

Re:Why large companies and fast-moving startups are banning ... by imiric on Friday December 29, 2023 @05:17PM (#38810918)
Interesting. I'll give it a try, thanks. At first glance it reads like too much magic that I'd have to undo manually, but if it works reliably, it would save some time. Though usually it's not much work to figure out which commit to reference in `--fixup`. In short histories, I usually just use `HEAD~<n>`, instead of hashes.

BTW, thanks for all your open source work. <3 You're an inspiration!

Re:Why large companies and fast-moving startups are banning ... by burntsushi on Friday December 29, 2023 @06:56PM (#38811604)
It is a very nice bit of magic. I've been using it for years, and I don't think it has ever given me a false positive. Plenty of false negatives though, but it tells you. And then you just fall back to what you've been doing anyway. It is literally a tool that has removed a fair amount of tedium from my workflow.
Re:Why large companies and fast-moving startups are banning ... by IshKebab on Friday December 29, 2023 @05:00PM (#38810756)
> making each step revertible

...

> CI jobs need to run

A step is only revertible if the previous state has passed CI, and as you noted that only happens if it is a separate PR.

The only reason to split a PR into separate commits it to make it easier to review and understand. But if it's so big you need to do that, it should be separate PRs anyway really.

IMO the only time you should ever preserve branches when merging them is if they're long-lived ones that multiple people have worked on and the commits in them have passed CI.

Re:Why large companies and fast-moving startups are banning ... by atq2119 on Friday December 29, 2023 @05:48PM (#38811137)
> But if it's so big you need to do that, it should be separate PRs anyway really.

The problem with that in practice is that the commits often depend on each other and then you have a choice of:

- serializing the PRs, i.e. only have one PR outstanding at a time, which increases your development latency; or

- no native UI for tracking how the PRs relate to each other

Yes, there are people trying to hack around the second problem. Still, the story there is far from great.

The CI thing is a real issue, I'll give you that. Though it is obviously also solvable, if the will for it were to exist.

Re:Why large companies and fast-moving startups are banning ... by IshKebab on Saturday December 30, 2023 @07:30AM (#38814787)
> serializing the PRs, i.e. only have one PR outstanding at a time, which increases your development latency

I don't see a significant downside to this. It doesn't affect my development latency - if the commits depend on each serially other then you have to wait for them to be reviewed in order whether or not they are separate PRs.

I do agree that GitHub/Gitlab don't support dependent PRs very well. You pretty much have to wait for one to be merged before submitting the next. Not a big problem in practice but it could definitely be improved.

Re:Why large companies and fast-moving startups are banning ... by TheCleric on Saturday December 30, 2023 @01:04PM (#38817197)
Once you start doing serialized PRs then doing squash merges increases your chance of a nightmare.

For example you have PR 1 and PR 2 (based on 1). Squash merge PR 1 into main. But while 2 is under review someone merges in 3 into main and you need to bring it into 2 to resolve some conflicts. You’re now hosed because the changes done in 1 are now present TWICE. First in 1’s commit, and also in the squash commit. Now you’re resolving all of 1’s changes as merge conflicts.

This may sound like a contrived examples but it has happened to me EVERY time I’ve worked somewhere that demands squash commits. And this is one of the reasons I hate squash commits.

“Makes the history prettier” vs “Rewriting the actual commit history”. Telling the truth > pretty.

Re:Why large companies and fast-moving startups are banning ... by IshKebab on Saturday December 30, 2023 @05:02PM (#38819678)
Ah I think where you're going wrong is trying to merge master into PR 2. Instead you should just rebase PR 2 on top of master. Git will automatically figure out that PR 1 has been merged and drop it. If it doesn't for some reason you can just do an interactive rebase.

Git history isn't "the truth" until it's shared. There's absolutely no issue rewriting history history for your own edits that nobody else is using yet. You do that every time you press undo!

Re:Why large companies and fast-moving startups are banning ... by atq2119 on Sunday December 31, 2023 @06:06AM (#38823212)
> Git will automatically figure out that PR 1 has been merged and drop it.

Unfortunately, that part doesn't work if you let GitHub do a squash, because then the commit on main has no corresponding commit on (the branch of) PR2.

When cherrypicking the commits corresponding to PR1 during the rebase, the merge algorithm will notice that the change is already there and notify you of the empty commit if the change is completely identical. But if it isn't, that falls down.

It's still not too difficult to recover, but it's annoying.

Re:Why large companies and fast-moving startups are banning ... by IshKebab on Sunday December 31, 2023 @06:12AM (#38823242)
> Unfortunately, that part doesn't work if you let GitHub do a squash, because then the commit on main has no corresponding commit on PR2.

Did you try it? It does still work. Git will detect that the changes are identical and drop it, even if the commit hash is different.