Accepting a messy git history

16 points by qznc


markerz

I really like stacked PRs, but not for any reason mentioned in the blog post. Personally, I think stacked PRs are significantly easier to get reviews and approvals for, and to get merged.

A single PR with multiple commits is hard to review because the tooling sucks. GitHub is really awful at separating this, and it's not immediately obvious a PR should be reviewed commit-by-commit, or if the commits are all WIP and you should review the resulting PR. God forbid someone comments on a change at the bottom of your commit chain, and you have to git rebase. I've messed this up a few times. I used to amend my commit chain to address PR feedback, but if you mess that up and force-push, you can't undo it because you lost history. You can make more commits, but if your PR has a non-trivial amount of feedback, the commit chain grows too long. Even worse, now people are reviewing commits that are stale because you've addressed things in subsequent commits! Stacked PRs solves reviewing with a reasonable user experience.

I often need reviewers for different parts of the code. I can separate a larger change into a stack of 3-4 smaller changes, and each team can review their smaller section.

People will easily approve a PR if they can review it within 5 minutes, and are willing to push up to 15 minutes. Anything that takes more time than that people will pass over. The review time is not proportional to size of PR. Larger PRs take WAY more time because there’s so much more jumping around and keeping things in mind with bigger PRs.

Some stacks cannot be merged all at once, like a squash merge. For example, a DB migration or some infra changes may need to be merged and deployed before dependent changes can be merged and deployed. As such, you need to merge one PR and then another, but it's very helpful to have your top PR be fully testable so you know everything fits together nicely.

The main flaw I see is that if you have to git revert, you might need to do so on a stack of merge commits instead of a single merge commit. Additionally, I have to be extra diligent at explaining that I'm using a stack of PRs that all tie together into a larger story, but that's just for the history. But the number of times I run into these “history” problems is extremely eclipsed by the number of times I need reviews on a PR.

ThePaulMcBride

I tend to see commit messages in a PR as the story I tell the reviewer to make it easier for them to understand what I'm doing and why.

We use squash and merge to make sure things stay sensible on a repo level. That also means that a rollback/revert is much more likely to work on a single commit.

deejayy

I'm not sure about you folks, but I can count on a single palm how many times I actually looked at git history to understand the state of things. Usually I live with the code as it changes (doesn't matter if I did these changes or not). If I don't, then it might be too big to catch anyway.
If you want a "clean history" to see what happened, then accept that sometimes things happened parallel, you know, because of the team structure/work schedule. There were typos, missed shots, all contributing to where the source is at.
Plus, how much time back a git history is useful? 3 months, 3 years? Do you walk forward or back? Forward walking needs you to understand approaches maybe long replaced, backward faces you with an already complete product which you need to understand before you can start reading. I usually let the team choose whatever they want to the point it is not obstructing my way and if it does despite, I'll hand it out to whoever chosen that approach.