this post was submitted on 08 Mar 2024
46 points (97.9% liked)

Programming

16760 readers
74 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

For non-trivial reviews, when there are files with several changes, I tend to do the following in Git:

  1. Create local branch for the pr to review
  2. Squash if necessary to get everything in the one commit
  3. Soft reset, so all the changes are modifications in the working tree
  4. Go thru the modificiations "in situ" so to speak, so I get the entire context, with changes marked in the IDE, instead of just a few lines on either side.

Just curious if this is "a bit weird", or something others do as well?

(ed: as others mentioned, a squash-merge and reset, or reset back without squashing, is the same, so step 2 isn't necessary:))

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 25 points 5 months ago (1 children)

If you were reviewing a "non-trivial" PR from me, I'd recommend not squashing because I would've broken it up into readable atomic commits.

[–] [email protected] 3 points 5 months ago (2 children)

This should be much more wide-spread. The hardest part of programming is reading someone else's code.

More people should learn to do git rebase -i, it's a simple way to re-organise your commits to make sure that they tell a story to someone going through the PR commit by commit. It only takes a minute and can save your colleagues so much time and increase the quality of the review process.

[–] [email protected] 2 points 5 months ago* (last edited 5 months ago)

Or use a tool like StackedGit which makes the atomic commit workflow incredibly simple. Build atomic commits as you go instead of after you've written all of the code.

[–] [email protected] 2 points 5 months ago* (last edited 5 months ago) (1 children)

Unfortunately it's uncommon now that GitHub's PR workflow dominates, so people think in terms of (often squashed) PRs and talk about "stacking PRs". At least GitHub supports viewing PRs commit by commit.

If PRs are just how it's going to be, I wish GitHub could auto cut stacked PRs from a linear branch of commits.

[–] [email protected] 1 points 5 months ago (1 children)

It's surprising how Github is sorely lacking in git features and even encourages bad practices.

  1. There is only a linear history view of commits without any child/parent relationships visualized. I have coworkers that tell me it's annoying how I use merge commits because they just see a big list of small commits in the history, and they'd rather see one commit per PR. Well... I sympathize, but also, fuck that! I'm not squashing my carefully crafted commits because Github has a shitty UI. Use git log --first-parent or something like lazygit. It's sad that many open source projects have adopted a "squash and merge" mantra for PRs. All of the merge methods have a valid use case, but people are so beholden to the damned Github history view.

  2. PRs have no concept of what a patch is. If you rebase, the entire history disappears. Reviewers cannot see changes made to individual patches unless they are applied first in new commits and then manually squashed into old patches after the review is done. Phabricator does this better IMO; each patch has its own history. I've even heard devs at other companies tell me they never make PRs bigger than 100 LOC. That just seems like a huge waste of time to me, unless you have some special tools to support that bizarre workflow.

  3. Merge queues only support a single merge method, one of merge commit, rebase, or squash. So we just don't use this desirable feature because of this limitation.

[–] [email protected] 2 points 5 months ago* (last edited 5 months ago)

Ooh yeah PR as patches, persistent despite rebases, would be nice.

Many git operations fundamentally have three SHAs as parameters (tree operations after all), and GitHub's model simplifies it down to two.