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

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.

1

u/GodsBoss Aug 20 '25
  • Refactor persistence layer to be more generic <--- This introduces a bug somehow not found by tests.
  • Add user creation.
  • Add editing users.
  • Add user search.

With squash merging, this will let me inspect all the code of those four commits, without it's only the relevant one.

1

u/PabloZissou Aug 20 '25

Why are you mixing a feature about persistence with a feature that uses that persistence? Same as the other commenter you are justifying squash vs not squash based on a convoluted approach at building a system I think? Wouldn't make more sense to have 2 different squash commits

  • refactor persistence layer
  • add user feature

If you have bugs across features in those commits your planning or architecture is all over the place probably

0

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

Why do you think that they have little value? What I've wrote is based on experience, specifically working with a lot of legacy projects. I've seen what works and what didn't. A single commit with feature: user management invites bloat and tend to change multiple places, ultimately being unusable when trying to work with history. Commits like "fixed pr comments" are pure noise and shouldn't be merged separately in the first place.

Writing good commit messages and keeping them atomic is precisely about keeping the commit history relevant in the future. You won't be scanning it (except bisect), but you might use blame - to understand the context.

And as a personal note: squashed pr's are usually unusable, with most of the teams; most of the developers. As much value as "project copy final FINAL"

→ More replies (5)

3

u/lovin-dem-sandwiches Aug 19 '25 edited Aug 19 '25

Let’s say your user test is failing causing the CI to reject any future changes. They need to revert your test commit but since it’s squashed - they’ll be forced to revert the entire PR/commit

Nothing wrong with squashing useless commits into one - as long as PRs/commits are atomic enough to revert isolated changes.

15

u/PabloZissou Aug 19 '25

Why would you merge something to main with unstable tests?

8

u/ryeguy Aug 20 '25

The PR is your unit of change because it is your unit of deployment. Reverting individual commits is nonsense.

15

u/JimDabell Aug 19 '25

If your user test is failing, the whole thing should be rolled back – because the test is failing and the feature never should’ve been merged in the first place with a failing test.

12

u/0vl223 Aug 19 '25

There is a reason you did combine them into one pull request. If too much gets rerolled then you failed at keeeping your PR atomic.

-1

u/Jazzy_Josh Lead Software Dev Aug 19 '25

Use interactive rebase and fixup to:

  • Add user creation
  • Add user edit
  • Add user search

6

u/imagei Aug 19 '25

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

-3

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

In terms of...? :)

Squash by default is detrimental, because no one will care in the future about the pr when using the history. If, of course, the change is atomic - then by all means, squash it!

But when you have some changes that are formatting of unrelated files (because you did revert most of the changes), some more related to the generic engine, and another part related to implementation - keep them separate. Rule of thumb - if you need to use "and" to describe the commit, split it.

But to do that efficiently, you need tools. I'm talking chunk splitting, amend --fixup, interactive rebase - tools that frankly most of the Devs don't even know about. And then we talk GitHub, which really really did dirty to git - from hiding graphs, up to making review of a multi-commit change far harder.

8

u/[deleted] Aug 19 '25

But when you have some changes that are formatting of unrelated files (because you did revert most of the changes), some more related to the generic engine, and another part related to implementation - keep them separate. Rule of thumb - if you need to use "and" to describe the commit, split it.

Why are you grouping unrelated changes into the same PR in the first place?

2

u/nickelickelmouse Aug 19 '25

I’m guessing it’s to minimize PRs reviewed by teammates.

7

u/[deleted] Aug 19 '25

Sounds counter productive as reviewing several PRs is way easier than 1 big one.

→ More replies (3)

2

u/edbrannin Aug 19 '25

Another cause that happens sometimes:

  1. Start tracking down the cause for a bug.
  2. Improve Component A because you suspect that’s what’s breaking stuff.
  3. It was not Component A, but it was still a good change so let’s leave it in.
  4. (Maybe repeat steps 2-3 a couple times, and maybe revert some of them if they aren’t good changes overall)
  5. Find the real root cause in Component C and fix it.

Now there’s a PR that makes some minor changes to several components (maybe improving logging, maybe beneficial algorithm changes or good refactors), and that also fixes the bug.

Sure, sometimes it’s easy to isolate the bug fix in its own PR and have a “misc. improvements” PR as a follow-up. But sometimes it’s more tangled, and more work than it seems worth to separate.

2

u/imagei Aug 19 '25

Totally. Also: find the issue, but it’s unfixable without refactoring or changing something else, which triggers changes in a bunch of other places.

As you said, technically once you prove you fixed the issue you could split the « other » changes into a separate PR, but frequently the effort to do that is so great that it all goes into a single PR, with a bunch of comments explaining what’s what.

2

u/SpiderHack Aug 19 '25

Those pre-fixes can be PRs in and of themselves. A meaningful change that the other devs approve doesn't have to fully solve all problems.

And you can chain a few PRs in a row for your full ticket.

Maybe that is the difference in practice.

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

1

u/row4land Aug 22 '25

Nube here. Will you clarify what is meant by atomic? Thanks.

2

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

In simple terms - "does strictly one thing". Easy litmus test - if you write the detailed commit subject and you need to write "and", then it's not atomic :)

But that of course doesn't mean that you commit each test; but the content of a commit is a coherent whole. I'll use example of one Redditor here:

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

I'd have three commits here:

  • Add user creation
  • Add user edit
  • Add user search
  • (And maybe, after some time) Fix flaky tests in user creation

Now imagine that we first need to do formatting on a code - usually, the developer would just reformat file while add the functionality to the customer, having a commit Add customer creation and formatting. But then, several things happen:

  • You can't clearly see what it's changing in diff, as the "real" change is hidden by the formatting
  • When trying to revert, you not only remove things related to 'add' but also formatting

So, atomicity requires that you do a commit beforehand - `Format the User service'. This way the subsequent commits can focus on the actual change.

As should be obvious, if you have the squash-merge enabled, then all these changes would be lumped together. That's why - avoid squash merge if it breaks atomicity.