by Olshansky · 2y ago · 0 comments
I'm comfortable git fooing w/e is necessary, but ever since we adopted this, git related conversations went to almost zero. It's great.
My reviewers love when I write “review commit by commit” in the PR description. Then each individual commit has its own reasoning, and you can mentally switch into reviewing if that commit does it’s one thing it’s supposed to do correctly. I will accept the argument that each commit should be its own PR though :)
The PR is just the best GitHub had to offer. There are other approaches to code review.
[1] Here we are generalizing.
It is not anemic like the squash workflow.
The PR is the unit of work, people get too hung up on the PR's individual commits.
Worst: rebase and merge - you end up with your coworker's broken WIP commits all over master, and have a terrible git revert story
OK: merge commit - you can revert, but there is a less intuitive `-m 1` flag (IIRC?) you have to pass into revert, and IMO you rarely need the intermediate history.
Best: squash & merge - you get one single commit representing the unit of work merging in, git revert is dead easy
Also setting the commit message in main to the `{title} (#{prNum})\n\n{prDescription}` format preserves all the good context from your PR and lets you get back to it if you need.
1. You get rid of WIP commits, typo fix commits, all kinds of transient changes (for review and so on)
2. You keep the substantive ones
3. All changes are logically separated
I don’t see where you cover this option.
> Also setting the commit message in main to the `{title} (#{prNum})\n\n{prDescription}` format preserves all the good context from your PR and lets you get back to it if you need.
Again. It is ironic that people are so comfortable with dumping the history in a webapp when you are working with a version control system.
I am fine with a lot of the history being on GitHub or whatever other webapp. The review history, that is. But I’m not comfortable with leaving the history of the pre-squashed commits on GitHub if those pre-squashed commits were useful for the long-term history.
And if the PR author deems their commits insignificant, they can feel free to make one PR and they squash & merge.
Vanilla tools make PRs have a certain overhead. Dependent branches and flipping from the terminal or IDE to the webapp and so on.
And these vanilla tools are often a team requirement. But with git(1) you can work around all that overhead.
Am I gonna stop weirdly insisting on using the version control system itself for version control instead of latching onto whatever passes for “PR”? Apparently not.
IMHO the guideline should be "clean up your branch and rebase it before merging. Usually that means a single commit, but it can be multiple if that makes more sense to <future person> reading the history".
In my experience, engineers tend to fall into 1 of 2 camps: 'Deep' Git knowledge who routinely dig through reflog and keep backup branches, commit early/often and autosquash logcal chunks until their PRs tell a Story through their commit history. The other side pretends git is p4; and has no concept of fetch vs pull vs rebase. A base assumption that branches are expensive and to be avoided.
I'd like to think probably fall in the middle, but nearly every engineer I've worked with falls on those edges based on the number of DMs i get asking for help after after the rote `git stash; git pull; git stash pop` throws conflict.
The problem with the squash strategy is when it is used as a team-wide policy. Like it was described here. I can’t understand why we have to collectively limit ourselves like that.
Another nice thing with squashing is that merges into master always look the same regardless of individual engineer workflows.
Commit history on a (larger?) PR tends to be most useful during the PR itself; I tend try and make my commits tell a story I can walk people through (on the CLI during a call) moreso than anything that will be useful in 6mo/year.
I've been convinced on Squash/Merge. If the PR needs more granular commits; maybe it should be 2 independent PRs.
We constantly use that on the OSS project I’m occasionally involved with. “Well why is it like that…” and the project has enforced a good history so this can often be answered.
And that’s the primary benefit of Git. With some discipline the history becomes legible.
On the other hand it doesn’t give you much out of the box for code review. Unless the code review you use is covered by the email tooling.
And so there is no reason to interfere with anyone’s way of working.
I firmly believe GitHub makes reviewing individual commits in a PR so painful that I'd rather not do that.
No. This kind of policy has plenty of downsides[1] and the upsides are relatively minor.
But I can’t relate in general to those workflows where PRs have to be tiny and revertable (why need to revert so often).
Having your git history reflecting this is great when you need to take decisions. Because no one will care about your individual commits. Every discussion will revolve about the task. So you make the PRs a bijective relation with it, and by extension the commits on the main branch. Then for special group of tasks like features, you have a specific branch you manage the same way. The other branches you create PRs from can be as messy as you like. And your local copy is yours to do whatever you want.
And yet that’s not usually what the problem is with having your canonical history “over there” in a proprietary webapp.
But if the history is easily available on those PR refs then I guess it is (under doubt) fine.