this post was submitted on 04 Apr 2024
1118 points (98.1% liked)

Programmer Humor

23030 readers
1511 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 2 years ago
MODERATORS
 
(page 5) 39 comments
sorted by: hot top controversial new old
[–] [email protected] 6 points 1 year ago

I like rebase, it's everyone else that hate it when I rebase main twice a day.

[–] [email protected] 51 points 1 year ago* (last edited 1 year ago) (8 children)

I prefer to rebase as well. But when you're working with a team of amateurs who don't know how to use a VCS properly and never update their branc with the parent branch, you end up with lots of conflicts.

I find that for managing conflicts, rebase is very difficult as you have to resolve conflicts for every commit. You can either use rerere to repeat the conflict resolution automatically, or you can squash everything. But when you're dealing with a team of Git-illiterate developers (which is VERY often the case) you can either spend the time to educate them and still risk having problems because they don't give a shit, or you can just do a regular merge and go on with your life.

Those are my two cents, speaking from experience.

[–] [email protected] 18 points 1 year ago (18 children)

I agree that merge is the easier strategy with amateurs. By amateurs I mean those who cannot be bothered to learn about rebase. But what you really lose there is a nice commit history. It's good to have, even if your primary strategy is merging. And people tend to create horrendous commit histories when they don't know how to edit them.

load more comments (18 replies)
load more comments (7 replies)
[–] [email protected] 15 points 1 year ago (2 children)

I'll go one further: use git rebase --interactive

[–] [email protected] 22 points 1 year ago (3 children)

I remember learning about how to use this back in the day and what a game changer it was for my workflow.

Today I like to do all of the commits as I’m working. Maybe dozens or more as I chug along, marking off waypoints rather than logging actual changes. When I’m done a quick interactive rebase cleans up the history to meaningful commits quite nicely.

The fun part is that I will work with people sometimes who both swear that “rewriting history” is evil and should never be done, but also tell me how useful my commit logs are and want to know how I take such good notes as I go.

[–] [email protected] 21 points 1 year ago (1 children)

Argh. I hate that argument.

Yes - "Rewriting history" is a Bad Thing - but o argue that's only on 'main' (or other shared branches). You should (IMHO) absolutely rewrite your local history pre-push for exactly the reasons you state.

If you rewrite main's history and force your changes everybody else is gonna have conflicts. Also - history is important for certain debugging and investigation. Don't be that guy.

Before you push though... rebasing your work to be easily digestible and have a single(ish) focus per commit is so helpful.

  • review is easier since concerns aren't mixed
  • If a commit needs to be reverted it limits the collateral damage
  • history is easier to follow because the commits tell a story

I use a stacked commit tool to help automate rebasing on upstream commits, but you can do it all with git pretty easily.

Anyway. Good on you; Keep the faith; etc etc. :)

[–] [email protected] 5 points 1 year ago

The only other time rewriting history might be bad is when you’re working on a shared branch, which is the point of not rewriting main. If you are working solo on a branch, its history is only what you merge into main so it doesn’t fucking matter at all. If you’re not working solo, maybe you need to adopt a similar process or look at how you’re not working solo. The only time I touch another dev’s branch is at the PR stage and only for quick corrections or missing knowledge so it doesn’t matter if they rebased before or honestly rebase after before the final merge.

[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

At my company we just use a squash policy in gitlab. Every merge request becomes a single commit to the main branch. Super easy to read the commit log because all commits are descriptive instead of a bunch of “fix MR comments” or “fix pipeline errors”.

Another advice: git reset [commit-id] followed with a git commit -a is a quick way to squash all your commits.

[–] [email protected] 2 points 1 year ago (2 children)

Another advice ...quick way to squash all your commits

in your IDE select the commits you want to squash. Then rightclick. Then "squash". All done.

load more comments (2 replies)
load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 2 points 1 year ago

do it often. you may end up with 150 conflicts to have to wade through.

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

You try to pull someone's changes, but whoops, they used rebase and rewrote history! Delete the branch and start over.

[–] [email protected] 9 points 1 year ago (2 children)

No you just do a rebase to bring it in. Assuming you’re making atomic commits you shouldn’t have a ton of merge conflicts. If you have to do this a lot, your branch scope is really bad and the problem isn’t in how you’re using got, it’s in how you’re slicing work.

load more comments (2 replies)
load more comments (1 replies)
[–] [email protected] 23 points 1 year ago (1 children)

Imagine working with a tangled spaghetti of history

load more comments (1 replies)
[–] [email protected] 86 points 1 year ago

History is written by the squashers.

[–] [email protected] 20 points 1 year ago (2 children)

I've been using merge, and I hate that I don't even know what rebase really does

[–] [email protected] 52 points 1 year ago* (last edited 1 year ago) (8 children)

Merge takes two commits and smooshes them together at their current state, and may require one commit to reconcile changes. Rebase takes a whole branch and moves it, as if you started working on it from a more recent base commit, and will ask you to reconcile changes as it replays history.

[–] [email protected] 13 points 1 year ago (3 children)

This diagram seems wrong to me. Isn't the second image a squash merge? Also why would rebasing a feature branch change main?

[–] [email protected] 2 points 1 year ago

why would rebasing a feature branch change main?

the image does not update the feature branch. It merges the featurebranch into main with a regular old merge-commit on the main branch.

load more comments (2 replies)
[–] [email protected] 6 points 1 year ago (2 children)

That's pretty cool, might actually do that. Tho, we currently don't use the history as much anyways, we're just having a couple of small student projects with the biggest group being 6 people. I guess it's more useful if you're actually making a real product in a huge project that has a large team behind it

[–] [email protected] 3 points 1 year ago (3 children)

I wouldn't recommend it. The Git documentation itself doesn't recommend rebase for more than moving a few unpushed commits to the front of a branch you are updating. Using it by default instead of merge requires you to use --force-push as part of your workflow which can lead to confusing situations when multiple developers end up commiting to the same branch, and at worst can lead to catastrophic data loss. The only benefit is a cleaner history graph, which is rarely used anyway, and you can always make the history graph easier to read with a gui without incuring any of the problems of rebase.

[–] [email protected] 6 points 1 year ago (4 children)

Bad take IMO,

At 10+ YOE, I use rebase almost exclusively. Branch from main, rebase to clean up commit history before putting up a PR. If commits are curated properly you don't run into conflicts very often. Branches really shouldn't be shared too often anyway, and the ones that are should be write protected.

Catastrophic data loss isn't really possible either with git since it's all preserved and you can git reflog even if you mess up.

The meme is right. Git good

load more comments (4 replies)
load more comments (2 replies)
[–] [email protected] 5 points 1 year ago* (last edited 1 year ago) (12 children)

Just remember to not combine it with force push or you're in for some chaos (rewriting history team members have already fetched is a big no-no).

load more comments (11 replies)
load more comments (6 replies)
[–] [email protected] 20 points 1 year ago* (last edited 1 year ago) (2 children)

Merge is taking all the code from the master branch and combining it with the task branch, resulting in a commit for just the merge itself.

Rebase is "re-basing" where your task branch was created from off the master branch. It essentially takes all the commits from master that happened since you branched, REWRITES THE HISTORY of your task branch by inserting those master branch commits before all your existing commits, and effectively makes your task branch look like it was branched yesterday instead of like 4 weeks ago. You changed where your task branch originated on the master. You moved its base.

Atlassian does a fantastic writeup on this.

[–] [email protected] 7 points 1 year ago (1 children)

So kinda like as if you had kept your branch synced the whole time?

[–] [email protected] 7 points 1 year ago* (last edited 1 year ago)

Kind of. Both merge and rebase result in the branches "synced up" but they do it in different ways.

Merge is making a batter for cookies, having a bowl for dry ingredients (task branch) and a bowl for wet ingredients, (master branch) making them separately and then just dumping the dry bowl into the wet bowl (merge).

Rebase is taking a time machine back to before you started mixing the dry ingredients, mix all the wet ingredients first then add the dry ones on top of that in the same bowl.

It's really hard to create an analogy for this.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

So, with a merge you basically shuffle in the changes from both branches, but a rebase takes only the changes from one branch and puts it over the other? Edit: no. Read wrong. I should probably watch a vid about it or something

[–] [email protected] 2 points 1 year ago

It inserts the master changes before the task branch ones.

[–] [email protected] 93 points 1 year ago (14 children)

Why is anyone using X in 2024?

[–] [email protected] 5 points 1 year ago

because some of the hardware I use is too old to run Wayland

[–] [email protected] -1 points 1 year ago

Because their name is Elon Musk.

[–] [email protected] 10 points 1 year ago

Because my new intel integrated graphics cause Wayland to run like a slideshow.

[–] [email protected] 16 points 1 year ago (4 children)

I tried it for a moment, made games stutter like hell, switched back. I know I need to go in and figure it out at some point, but it's hard to muster the energy when X, for the most part, works fine.

From what I've seen, it probably has to do with my Nvidia GPU.

[–] [email protected] 1 points 1 year ago

I'm currently at the point where I blame everything that works on my Laptop but not on my PC on Nvidia, because that's literally the biggest difference between those two. Like currently my getty isn't displaying properly, which is surely NVidias fault.

load more comments (3 replies)
[–] [email protected] 32 points 1 year ago* (last edited 1 year ago) (1 children)

I use X because Cinnamon on Wayland has no option to change the keyboard layout

load more comments (1 replies)
[–] [email protected] 198 points 1 year ago (2 children)

I do, I have yet to switch to Wayland

[–] [email protected] 38 points 1 year ago (2 children)

It's called Twitter now, by conservation of names. /s

load more comments (2 replies)
load more comments (1 replies)
load more comments (8 replies)
[–] [email protected] 2 points 1 year ago

I like the idea of it and there were times i used it correctly, but most of the time i do it wrong i guess.

load more comments
view more: ‹ prev next ›