r/ExperiencedDevs • • Aug 19 '25

Never commit until it is finished?

How often do you commit your code? How often do you push to GitHub/Bitbucket?

Let’s say you are working on a ticket where you are swapping an outdated component for a newer replacement one. The outdated component is used in 10 different files in your codebase. So your process is to go through each of the 10 files one-by-one, replacing the outdated component with the new one, refactoring as necessary, updating the tests, etc.

How frequently would you make commits? How frequently would you push stuff up to a bitbucket PR?

I have talked to folks who make lots of tiny commits along the way and other folks who don’t commit anything at all until everything is fully done. I realize that in a lot of ways this is personal preference. Curious to hear other opinions!

80 Upvotes

315 comments sorted by

View all comments

Show parent comment

140

u/SpiderHack Aug 19 '25

This is why I'm in favor of merges being squashes, cause I make dozens of "added logging" commits in hard bug tickets.

No reason at all to flood the gitlog with that nonsense, but as a dev that IS a logical chunk worth saving

66

u/potchie626 Software Engineer Aug 19 '25

We have rules set that our PRs can only be set to squash into the main branch.

60

u/Poat540 Aug 19 '25

Yeah exactly - devs do lots of commits - then squash into main - 100% the way

28

u/[deleted] Aug 19 '25

Just interactive rebase before you commit to clean up the commits.

100% the way.

25

u/Poat540 Aug 19 '25

Our team has never needed to rebase and our history is linear and clean

39

u/Illustrious-Wrap8568 Aug 19 '25

Linear and clean maybe, but the commits themselves are very likely not atomic, which means you lose a lot of granularity in why certain changes happened. Most people might as well have stayed on svn

11

u/[deleted] Aug 19 '25

If that is the case your PRs are too big.

19

u/Illustrious-Wrap8568 Aug 19 '25

Well, a pull request is a request to merge a branch into another. A PR can absolutely consist of a couple of sensibly formed commits that doesn't need squashing. I am of the opinion that if squash commits need to be the default, you really haven't been curating your commits properly. It also doesn't really encourage people to actually care about their actual commits.

→ More replies (7)

7

u/[deleted] Aug 19 '25

It’s funny how people downvote you, like this is some outrageous statement. How dare you suggest having a clean commit history?

5

u/DefinitelyNotAPhone Aug 19 '25

Why does a clean commit history matter if you're squash merging into your main branch? Doubly so if you need to push up to a pull request so your CI can run tests and spin up development environments, which means you'd need to clean up git history in multiple places.

0

u/[deleted] Aug 19 '25

[deleted] — view deleted comment

4

u/[deleted] Aug 19 '25

Squash merge does not prevent you from using git bisect whatsoever.

→ More replies
→ More replies (5)

3

u/dalbertom Aug 20 '25 edited Aug 20 '25

I think the problem is that often times people assume that linear history means clean history and that's not entirely true.

Squash-merge is great for beginners or for people that never recovered from prolonged svn exposure. But once people understand the benefits of merge commits they'll start noticing that squash-merge gets in the way, like using training wheels on a bicycle.

There's a reason why one of the main rules is to not rewrite someone else's history, and squash-merge (also rebase-merge) violate that. Under the pretense of "clean" history they end up with tampered history.

→ More replies (2)
→ More replies (3)

4

u/RandomNPC Aug 19 '25

I don't like having this as a rule because there are times where you want different commits. Probably not a problem for many codebases but for ours our commits can sometimes be thousands of files. That way we can break up the "this is just asset updates" commits from the code/logic changes.

Sure we could do them as separate PRs but the tests need both.

3

u/ub3rh4x0rz Aug 20 '25 edited Aug 21 '25

Tbh there's rarely a point in squash merging other than concealing deficiencies in the team's git fu. Just require merge commits, that logically groups the work. I prefer git bisect to be useful, among other benefits of preserving the granularity of history

5

u/edbrannin Aug 19 '25

Cautionary Tale

So, the problem with squash-and-merge comes up when two people work closely on something on different branches.

  1. Alice starts work on a feature, adding some new properties to a data-class. (Commit A)
  2. Bob starts some work that depends on those new properties, so he forks from Alice’s feature-branch. (Commit B)
  3. Alice’s PR merges, and is squashed into Commit C.
  4. Bob pulls from upstream, and everything in Commit A is marked as a conflict with the squashed Commit C.

Hot Take

All this for what? A prettier graph?

Why does it matter if the git history has a bunch of “added logging” and “whoops” mixed in?

(Serious question. It would be helpful to have a “this specifically is what’s wrong with that” akin to the above steps.)

Just use regular merges and don’t mess with git history. It’s literally what happened.

11

u/SpiderHack Aug 19 '25

Why does it matter about added logging? Etc. ? Two main reasons: 1 is human psychology, you know people won't commit if they think things will be logged, I've taught enough intro to OOP classes that I've seen that at play. 2 you don't want git blame to be cluttered with a lot of nonsense.

"It is literally what happened" (on the devs machine) doesn't need to be the same as "what changes we want to save to the community log".

The gut graph is the least important part of git IMHO, git blame for a line or file is way more significant. I work in a code base that is 15 years old, if I'm in a file that has 1 month old edits, it is quite easy to see where the likely issue arose from. But if we had logged every debug step taken (it doesn't have great logging, and is something on my backlog to improve) then the file would be way more cluttered with random commits.

→ More replies (4)
→ More replies (1)

14

u/Venthe Systems Designer, 10+ YOE Aug 19 '25

This is why I'm in favor of merges being squashes

As long as they are atomic. In my experience, most of them aren't; so squashes are ultimately very detrimental to the git history and futureproofing the application.

I really wish people would learn git beyond three commands.

39

u/difudisciple Aug 19 '25

If we’re talking about the main branch, squashing (ala linear history) makes bisecting issues and rollbacks much easier to manage.

If you need more granularity that that, then work should be split into smaller PRs

4

u/GodsBoss Aug 20 '25

If we’re talking about the main branch, squashing (ala linear history) makes bisecting issues and rollbacks much easier to manage.

We had this exact discussion in our team a few days ago. How does it improve bisecting if the commit I find is a squash commit and does contain more code than a non-squashed commit?

Not sure about the rollback thing. Do you mean reverting to a previous state?

→ More replies (1)

14

u/PabloZissou Aug 19 '25

Wait so let's say I have

  • add user creation
  • add user edit
  • fix flaky user test
  • fix edge case for user
  • PR feedback
  • add user search
  • fix user creation again
  • PR feedback II
  • fix test

Is better than having a single commit in the main branch

  • feature: user management

?

What's the value of the intermediate commits? Why fix with local squash when you can land a full feature into the main branch after review and all is ready for release?

6

u/Venthe Systems Designer, 10+ YOE Aug 19 '25

I'll just drop the resource, it explains it way better than I would do anyway.

https://cbea.ms/git-commit/

In short, I'd probably fixup-rebase that history to ~3 commits. Add user search, add user edit, add user creation. The rest would be squashed/fixup'ed

10

u/PabloZissou Aug 19 '25 edited Aug 19 '25

What's the value of the intermediate commits that on their own have little value?

Edit: I think you are missing the point is not about writing good commit messages is about the lack of value of keeping commit history for intermediate commits which if anything making scanning main or feature branches slow and, if needed, git bisect slower. But well I guess it's a matter of what is valued on each project.

→ More replies (8)
→ More replies (6)

6

u/imagei Aug 19 '25

I agree with the sentiment, but what are you suggesting exactly ?

→ More replies (17)
→ More replies (2)
→ More replies (5)