News for hackers. Stuff that matters.
Re:Gitless a simple VCS built on top of Git by rmccue on Saturday June 17, 2023 @11:42AM (#36371189)
If you’re including rebasing, then I can believe this (rewriting history is nuanced and complex), but I’m not sure I’d be teaching that straight away. My recommendation is usually only to start using rebase once you’re already very familiar with the rest of git, since it’s almost never necessary to achieve what you want.

Also, bisect is definitely not common, and the vast majority of my colleagues wouldn’t know it exists; I’d place it into the look-it-up-if-needed category.

Re:Gitless a simple VCS built on top of Git by ranaexmachina on Saturday June 17, 2023 @12:41PM (#36371853)
If you teach all the concepts of Git (e.g. commits point to parents but not to children or branches are labels that point to a commit) properly it takes some time but then you get a lot of the more advanced things such as rebase kind of for free. In my experience, people often struggle with those because they have no clue how Git internally works. I had the same problem but when I looked into that it clicked and suddenly all the commands made a lot more sense.
Re:Gitless a simple VCS built on top of Git by jedberg on Saturday June 17, 2023 @12:27PM (#36371676)
> I’d place it into the look-it-up-if-needed category.

Knowing how to use git bisect is what elevates a programmer to the next level. Just understanding how it works gives you a new way to reason about bug finding and fixing (or feature development using old and new), and then actually using it can make you a bug fixing master.

Re:Gitless a simple VCS built on top of Git by pydry on Saturday June 17, 2023 @12:31PM (#36371714)
It feels like a weird and magical superpower but realistically I find use for it about once every 6 years and even then I'm fairly sure I could have done without it.

This was not my impression when I first learned about it. I thought I'd be using it all the time.

Re:Gitless a simple VCS built on top of Git by jedberg on Saturday June 17, 2023 @12:36PM (#36371783)
> and even then I'm fairly sure I could have done without it.

Just understating how git bisect works is the real superpower. The tool is a nice add on, but often you're right, is easier to bisect by hand by going to a known working commit and then doing a smart bisect based on the code you think might be offending.

But at least knowing the concept of bisection is a huge game changer.

Re:Gitless a simple VCS built on top of Git by pixelpoet on Saturday June 17, 2023 @02:11PM (#36372785)
I'm pretty sure every programmer learns about binary search near the beginning, and even without that has searched through some alphabetical listing without starting at aardvark (if not, I'd argue they have zero hope at much of anything abstract).

Really feels like a stretch to credit git, of all things, with that fundamental understanding. It's like saying you need to operate a nuclear power plant to understand the benefits of locking doors.

Re:Gitless a simple VCS built on top of Git by xenomachina on Saturday June 17, 2023 @02:41PM (#36373137)
When people search through alphabetical listings, they usually don't use plain old binary search, but instead use something like interpolation search. For example, if you want to find the word "xylostroma” in the dictionary, you aren't going to start in the middle. Instead, you'll start about 90% of the way through, and then make adjustments based on how far off you were.
Re:Gitless a simple VCS built on top of Git by lost_tourist on Saturday June 17, 2023 @05:29PM (#36374833)
Yeah but that is only optimal if you know the general location. Often when you have a bug you don't know where it snuck in, especially if it's something like a race condition.
Re:Gitless a simple VCS built on top of Git by xenomachina on Sunday June 18, 2023 @02:45AM (#36377917)
Sure. My point was just that contrary to what programmers typically think, people don't use binary search to look up things in a dictionary.
Re:Gitless a simple VCS built on top of Git by rmccue on Saturday June 17, 2023 @01:10PM (#36372135)
I don’t disagree, and I personally use it, but it’s a decent distance from teaching students the basics of git. I’d bundle it into a group of tools that are useful to know the existence of, and look up the docs when needed.
Re:Gitless a simple VCS built on top of Git by cassianoleal on Saturday June 17, 2023 @12:08PM (#36371478)
> bisect is definitely not common

Agree.

> I’d place it into the look-it-up-if-needed category.

Disagree. Bisect is so useful in so many different scenarios that learning about it and the basics of how to use it is a great way to get people into git. Obviously not right at the beginning of their learning curve but as soon as the basics have been covered satisfactorily.

Re:Gitless a simple VCS built on top of Git by aaomidi on Saturday June 17, 2023 @12:40PM (#36371827)
I wish more people would know about bisect mainly because they’d design the toolchains to actually support testing when you’re doing bisect.
Re:Gitless a simple VCS built on top of Git by willio58 on Saturday June 17, 2023 @12:56PM (#36371995)
I’ve used git successfully professionally for almost 10 years and I’m not lying when I say I’ve used rebase about 5 times. We just merge. We squash sometimes. I think it must be because I’ve always worked in smaller orgs but rebase just seems to always be over complicating something simple (a merge). I get that there’s a benefit of a cleaner history but to me the benefit of simplicity merge offers makes it superior
Re:Gitless a simple VCS built on top of Git by ttfkam on Saturday June 17, 2023 @01:41PM (#36372447)
I always rebase from an up-to-date main/master before pushing my feature branches. So much easier to deal with than merging after the fact.

But yeah, after that initial push, it's just merges from there on out.

Re:Gitless a simple VCS built on top of Git by ahelwer on Saturday June 17, 2023 @01:04PM (#36372071)
You have to fix conflicts either way so what's the difference? I suppose when merging you only have to fix the cumulative conflicts, while when rebasing you have to incrementally fix the conflicts introduced by every commit which is annoying. I usually squash a branch (rebase on where it diverged) before rebasing to fix this.
Re:Gitless a simple VCS built on top of Git by halostatue on Saturday June 17, 2023 @01:27PM (#36372293)
It’s worth configuring rerere (reuse recorded resolution): https://git-scm.com/docs/git-rerere for merges and rebases, because repeated rebases or merges of similar code will become substantially easier.
Re:Gitless a simple VCS built on top of Git by frutiger on Saturday June 17, 2023 @01:36PM (#36372396)
> revere

Innocent typo but for anyone else reading, it’s “rerere”.

Re:Gitless a simple VCS built on top of Git by halostatue on Saturday June 17, 2023 @01:42PM (#36372457)
Thanks. I still had time to fix it, so I’ve corrected it. I had typed rerere, but autocorrect "fixed" it for me whether I wanted it fixed or not.
Re:Gitless a simple VCS built on top of Git by adontz on Saturday June 17, 2023 @01:44PM (#36372485)
After rebasing you basically have two versions of the same commit, and that is the root of the problem.
Re:Gitless a simple VCS built on top of Git by unmole on Saturday June 17, 2023 @02:56PM (#36373309)
> After rebasing you basically have two versions of the same commit, and that is the root of the problem.

No, you have two commits. Git commits are snapshots, not diffs. Git's data model is simple. The fact that people do not bother trying to understand it is the root of the problem.

Re:Gitless a simple VCS built on top of Git by adontz on Monday June 19, 2023 @09:38AM (#36390972)
I never stated otherwise, IDK what are you not agreeing with.
Re:Gitless a simple VCS built on top of Git by p1esk on Saturday June 17, 2023 @02:33PM (#36373043)
Why is this downvoted?
Re:Gitless a simple VCS built on top of Git by dtech on Saturday June 17, 2023 @01:42PM (#36372459)
squashing is a form of rebasing, albeit a narrower and simpler case. Indeed I do not understand why rebasing is so popular instead of merging when you're going to squash at the end anyway.
Re:Gitless a simple VCS built on top of Git by throwbadubadu on Saturday June 17, 2023 @01:43PM (#36372470)
Done right and understood, it is as simple as merging, if conflicts arise no difference to conflicts via merge?

But you get rid of those ugly merges back and forth and unviewable histories.. Not sure why not more people care, I guess it is a little OCD I do that for my stuff.. however the 20-50+ user projects where everyone, often multiple times merges develop or even other branches in.. really unusable history right away, lets not talk about any point later. Git has derailed to a mere backup system where you can jump back, but understanding changes later becomes impossible :(

What people also rarely know: A linear history is without lies, but one can sneak additional changes into a merge commit that was in neither branch quite easy - I hate that!

Re:Gitless a simple VCS built on top of Git by no_wizard on Saturday June 17, 2023 @05:38PM (#36374915)
My biggest issue with rebase from a learners perspective is that you get conflicts that simply don’t happen with merge.

I’ve had experiences where I’m trying to rebase a branch and it keeps flagging my most recent changes in the rebase when the intention is that I want all previous changes applied then as a final step show me a conflict if applicable, don’t show me one when it’s not the “final” step.

Admittedly maybe I’m doing it wrong.

I also don’t like how rebasing “main” onto my branch actually seemingly takes my branch and rebases it onto “main”? Maybe that’s a fault in my IDE not entirely sure

Re:Gitless a simple VCS built on top of Git by galaxyLogic on Saturday June 17, 2023 @06:03PM (#36375153)
I think the difficulty with rebase and merge is much about semantics. When you "rebase" what does that word suggest to you? To me it sounds like "Base Again". So I'm changing the base from which I started the current branch to something else?

Not quite. That would mean that my old base is REPLACED by something else, right?

Instead rebase means take some other branch then put all the changes in the current branch on top of it, keeping everything in the current branch but just adding them on top of something else, right?

It grokked with me when in my IDE (WebStorm) I saw the menu-option allowing me to choose another branch and perform "Check Out and Rebase on top of the current branch". So you don't just "rebase a branch", you combine two branches. And when you combine two things here the order matters, and it is easy to confuse the order.

Similarly if you merge two branches, which one overrides? The left or the right operand? It is easy to get confused. Maybe I am. It is not my fault.

Re:Gitless a simple VCS built on top of Git by jfengel on Saturday June 17, 2023 @06:51PM (#36375559)
It does not help that git really is checkpoints rather than deltas. The semantic difference is usually ignorable, but it can matter when you're trying to rewrite history. It's coming up with deltas on the fly, and if it gets confused it can get very very lost.

Every rebase really is at least three branches: what you're merging into, where you started, and where you are now. And God help you if somebody rewrote history on any of those.

The fact that all of these have terrible names makes it so much worse.

Re:Gitless a simple VCS built on top of Git by charrondev on Saturday June 17, 2023 @06:10PM (#36375218)
In my org we require all important data to be listed on a pull request, then enforce squash merge. If you have multiple distinct changes you want reflected in the history then you make multiple PRs.

This makes bisecting a lot easier too.

Re:Gitless a simple VCS built on top of Git by jfengel on Saturday June 17, 2023 @06:40PM (#36375459)
I really wish git bisect understood merges better, so that you didn't have to fake it with squash.
Re:Gitless a simple VCS built on top of Git by kazinator on Saturday June 17, 2023 @06:21PM (#36375302)
"enforce squash merge" == "pretend Git is Visual Source Safe or CVS"
Re:Gitless a simple VCS built on top of Git by formerly_proven on Saturday June 17, 2023 @06:36PM (#36375418)
> Not sure why not more people care

Most people don't care about most stuff, it's pretty normal.

But here specifically: Most developers don't read code, nor documentation, and essentially no one reads commit messages. VCS is a WOLM - write-only linear memory - to most developers. That's probably also why most people don't care to write any kind of reasonable commit message - the software requires them to input something, so something is input - and also do not care about unreadable (and also unusable) VCS histories. They're never looking at it, it's only written. Hence it's meaningless for them if it is extremely difficult to trace changes or hard to bisect, they don't even attempt such things. There's a reason the history browsers in all the online tools and IDEs effin suck, it's because on average nobody uses history.

I know, I know, this gets across very elitistically, but it's just how most people do their jobs. They get bugged to do a thing, so they sort of do the thing in order to not be bugged any more. I'm pretty sure that caring for these things is some kind of OCD like you say, i.e. a mental disorder.

Re:Gitless a simple VCS built on top of Git by adontz on Saturday June 17, 2023 @01:46PM (#36372501)
It highly depends of culture of specific team. I've seen teams obsessed with "clean" history, rebasing and squashing everything they possibly could. I believe it's a matter of taste, I never understood the argument.
Re:Gitless a simple VCS built on top of Git by loeg on Saturday June 17, 2023 @02:02PM (#36372685)
I use rebase essentially every working day. I use rebase for managing my local tree of patches, regardless of interaction with colleagues. Merge is fine, I guess, but do you never get the order wrong and want to reorder things before you push? Or keep moving around some local debugging patch on the top of your stack, without pushing it to your colleagues?

IMO merge is almost never what you actually want, unless you've been working separately for a long period of time (and generally you should not being doing that because it leads to surprising conflicts / regressions at merge time).

Re:Gitless a simple VCS built on top of Git by KnobbleMcKnees on Saturday June 17, 2023 @05:38PM (#36374922)
It depends what you mean by separately. Big organisations can have dozens of teams implementing unrelated functionality with asymmetrical overlaps for conflicts. I've never found a situation where rebase was appropriate for this kind of setup.
Re:Gitless a simple VCS built on top of Git by loeg on Saturday June 17, 2023 @05:57PM (#36375090)
If the functionality is unrelated, I'm not sure why rebase would be inappropriate. It just wouldn't matter much other than keeping history clean (and rebase would make for cleaner history than merges).
Re:Gitless a simple VCS built on top of Git by KnobbleMcKnees on Sunday June 18, 2023 @06:04AM (#36378802)
What is the benefit of this to isolated teams? Rebasing a shared main that is under a constant stream of PRs is tedious and time consuming. What is the justification of this in terms of time spent for a company paying for that time? How is that time recouped via the availability of a linear history?
Re:Gitless a simple VCS built on top of Git by bryanlarsen on Saturday June 17, 2023 @02:44PM (#36373169)
Rebase got a lot less annoying now that git has gained the update-refs ability. I'm often working on multiple branches simultaneously, and update-refs lets me easily work on them as a stack.
Re:Gitless a simple VCS built on top of Git by ptx on Saturday June 17, 2023 @03:09PM (#36373452)
How do you use it? It sounds (from the manual page) like it just changes what a branch points to... so how is it different from "git reset --soft"?
Re:Gitless a simple VCS built on top of Git by bryanlarsen on Saturday June 17, 2023 @06:13PM (#36375245)
Here's how i use it: I call my HEAD "bl-dev". Let's suppose I have 5 commits on bl-dev that aren't on main. Each of those commits is a branch with a functional name. If I type "git rebase --update-refs origin/main" all 6 branches get updated, not just bl-dev.

Let's suppose the next thing I do is add something to the bottom of my 5 branches. I dont switch to the branch, I stay on bl-dev and add a commit to bl-dev. Then I type "git rebase --update-refs -i HEAD~7" and move the commit up in the stack to the correct location and again all 6 branches update.

"git rebase --update-refs -i" also gains the ability to change which commit any branch points to.

I don't actually type "--update-refs", it's a gitconfig.

Re:Gitless a simple VCS built on top of Git by gte525u on Saturday June 17, 2023 @03:54PM (#36373924)
FWIW - I've worked with both rebase workflows and merge workflows. If you rebase a long lived branch what breaks is /your/ code not the rest of the codebase in a rebase workflow vs the opposite being true with merges.
Re:Gitless a simple VCS built on top of Git by kazinator on Saturday June 17, 2023 @06:19PM (#36375278)
Git merging is completely stupid. It collapses multiple changes into a single commit. The original chain of commits is referenced, but in a useless way that only complicates the git history.

When you merge 17 changes from foo-feature into master, master has only a single commit. You cannot bisect master to determine which of the 17 broke master.

The 17 commits are there, but only in their original form, based on some old commit. Those 17 original commits are not equal to the single merged commit. The single merge could have a bad merge.

If there is going to be a bad merge, it's better to have a bad merge in one of 17 commits being individually rebased, than to have a bad merge in a single merge bomb that conflates 17 commits.

Your little branch of the original 17 commits should be purely a private object; it does not belong in the upstream. It's just a historic accident that your work was originally based on some three-week old random commit that happened to be latest at the time when you started. There is no need for that to be published. Your job is to make sure your code is based on the latest commit and promote it to the branch, as a sequence of individual changes (which all build and pass unit tests, etc).

I've literally not typed "git merge" since 2010, and around that time I learned how not to have Git perpetrate unwanted merges on me by learning never to type "git pull". "git pull" can be configured to be "git pull --rebase", but you will forget. I trained myself to do "git fetch", then "git rebase".

In all my last three jobs, the review tool Gerrit was used. Gerrit is based on cherry picking, which is rebase. Commits are submitted in their original form (not necessarily rebased to the target branch, but indicating which branch they are for). When approved, they are submitted and that means cherry pick. Maybe Gerrit can merge; I've never seen it used that way. Gerit has rebase right in the UI. You can take a commit and rebase it to its logical parent (latest patch set of an apparent parent with which it had been submitted together), or to the current head of the branch.

Re:Gitless a simple VCS built on top of Git by lionkor on Sunday June 18, 2023 @04:58AM (#36378471)
At my last job, every branch has to be rebased before merge, leading to an incredibly clean history.
Re:Gitless a simple VCS built on top of Git by adontz on Saturday June 17, 2023 @01:49PM (#36372536)
I see bisect as a git superpower. Also grep (with rev-list). It's like knowing regular expressions. Not that one writes regexps every day, but this knowledge/skill definitely uplifts one to the next level.
Re:Gitless a simple VCS built on top of Git by lost_tourist on Saturday June 17, 2023 @05:30PM (#36374849)
I basically have to relearn regex's almost everytime, yeah it's a bit easier each time, but I still have to go back through some basic examples to get those old neurons stirring.
Re:Gitless a simple VCS built on top of Git by Jenk on Saturday June 17, 2023 @03:06PM (#36373420)
I don't know how successful of a metaphor this would be for students, but for developers who haven't had any familiarity with DVCS that I have worked with, I use a coat-rail analogy with some success:

You start with a "main" rail of coats. Each coat is given a number, indicating what order it is in.

You start adding coats to a new, empty, rail, using the next number. When you are done collecting coats on this new rail, you want to move your coats onto the original rail.

In the time it has taken you to collect the coats onto your rail, someone else has already added coats from their new rail to the end of the "main" rail, and they used the same base number that you have - which means you cannot just add the coats from your rail onto the main rail, else the numbering would be broken - we call this a conflict. (NB: There is a magic guardian of the rails that means this just cannot happen, which is a plot device that is just to make this metaphor work so don't question it, it's just a metaphor.)

To resolve the conflict you have the following "rebase" options:

- Slide all of the coats on the main rail up to make room for yours, and update all of the numbers on your coats, using the new number from the last coat as the base number for your rail's sequence. This ensures that everything on the main rail is "before" your rail. This is the equivalent of a rebase. After this, you can then put your coats on the end of the main rail without conflict.

- Then there is the option to take a copy of the main rail onto the front of your rail, and organising the coats one-by-one (much like in the above), placing your coat(s) in between some of the new coats on the main rail, then forcibly replacing the main rail with your updated rail. This last one is just as drastic in reality as it sounds in this metaphor. We call this the "interactive rebase" and it is rewriting history for anyone who has used the main rail before.

- Finally we have a merge which means adding one big magic coat at the end that takes the coats from both rails and combines them in a singularity, with the new base number being Hawking's radiation or something, I dunno. The metaphor is no good for merges.

(Truth be told: the entire metaphor started in my head some years ago with just the visualisation of that distinct coat rail sweep noise to squish the garments on the rail to onside to fit what our main protagonist is holding onto the rail, the rest I just back-filled over time)

Re:Gitless a simple VCS built on top of Git by jupp0r on Saturday June 17, 2023 @03:20PM (#36373592)
Rebase is used for many things in a lot of workflows. I use it probably 30 times per day in my job.
Re:Gitless a simple VCS built on top of Git by kazinator on Saturday June 17, 2023 @05:48PM (#36375013)
Using rebase is crucially important to anyone who is ready to start using git to track a remote repository and produce new changes to be pushed must learn about rebase. You have to use rebase to rewrite your unpublished commits over the latest upstream in order to be able to push a fast-forward change.

Many new users of git don't have the luxury of learning how to use local-only git with no remote.

Now rebase is a farm implement: a mechanized cherry picker. Cherry picking should be taught first, and then rebase explained in terms of being a multi-cherry-pick operation.

Before teaching cherry picking, you have to teach that Git is based on snapshots and not deltas. Git cherry-pick is part of tooling that is inside Git, but external to its snapshot-based storage model. When you cherry pick some commit into your current branch, the tool finds the common ancestor between your branch and that commit. It then does a three-way diff using the files in the cherry-picked snasphot, your own branch snapshot and the common ancestor-snapshot. The three-way diff operations produce a merged version that becomes a new commit: another snapshot.

If I ran a class on Git, we would spend part of a lecture doing manual merges with the diff3 utility: I would have the students take some ancestor file and make a "my" and "yours" with different changes, and merge these with diff3. We would go through conflict markers and all that.

Old time hackers who used other version control systems before Git knew all this stuff already. The first time I encountered conflicts, I already knew how to resolve them. Just a few git concepts were new like having to add resolved files to the index.

Imagine you know nothing about version control. Words like "unified diff" ring no bell. You've never seen conflict markers. You've never applied a patch or produced one.