424
you are viewing a single comment's thread
view the rest of the comments
[-] RustyNova@lemmy.world 38 points 4 months ago

NGL I 'm a bit like that. I often do "work" commits so that my working tree is a bit more clean/I can go from working state to working state easily.

But before a PR, I always squash it, and most times it's just a single commit

[-] DacoTaco@lemmy.world 4 points 4 months ago* (last edited 4 months ago)

Same haha. But i use a combination of commits ( but not pushed ), ammending, fixups and usually clean it up before making a PR or pushing ( and rebase/merge main branch while at it). Its how git should be used..

[-] RustyNova@lemmy.world 5 points 4 months ago

I do push often as I'm often switching between two devices. And I do make draft PR so I got an easy git diff that I can live reference with

[-] verstra@programming.dev 3 points 4 months ago

You are not alone. This is the work git was built for.

There is a bit of benefit if you have code reviewed so separate commits are easier to review instaed of one -900 +1278 commit.

[-] pineapplelover@lemm.ee 2 points 4 months ago
[-] veganpizza69@lemmy.world 4 points 4 months ago

Squashing

The s "squash" command is where we see the true utility of rebase. Squash allows you to specify which commits you want to merge into the previous commits. This is what enables a "clean history." During rebase playback, Git will execute the specified rebase command for each commit. In the case of squash commits, Git will open your configured text editor and prompt to combine the specified commit messages. This entire process can be visualized as follows:

Note that the commits modified with a rebase command have a different ID than either of the original commits. Commits marked with pick will have a new ID if the previous commits have been rewritten.

https://www.atlassian.com/git/tutorials/rewriting-history

You can also amend for a softer approach, which works better if you don't push to remote after every commit.

The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit. It can also be used to simply edit the previous commit message without changing its snapshot. But, amending does not just alter the most recent commit, it replaces it entirely, meaning the amended commit will be a new entity with its own ref. To Git, it will look like a brand new commit, which is visualized with an asterisk (*) in the diagram below.

You can keep amending commits and creating more chunky and meaningful ones in an incremental way. Think of it as converting baby steps into an adult step.

[-] RustyNova@lemmy.world 3 points 4 months ago

My attempt to explain was squashed by this comment

[-] mauzybwy@programming.dev 2 points 4 months ago

Or if you want to --force commit ๐Ÿ˜ˆ. Imo if it's my own working feature branch on a trunk-based roll-forward repo idgaf about rewriting history, and I will do it with wanton abandon.

[-] SparrowRanjitScaur@lemmy.world 2 points 4 months ago* (last edited 4 months ago)

Gitlab has a checkbox for squashing merge requests into a single commit. Not sure if GitHub has that too.

this post was submitted on 27 Jun 2024
424 points (95.5% liked)

Programmer Humor

19564 readers
1273 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS