Yeah learned this the hard way.

  • Eiri@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    24 days ago

    As long as you never touch the rebase button, you’ll be fine. Probably.

    • GissaMittJobb@lemmy.ml
      link
      fedilink
      arrow-up
      0
      ·
      23 days ago

      Don’t be afraid of rebases, they are an essential tool in Git.

      This particular fear can only be addressed by understanding.

      • Eiri@lemmy.ca
        link
        fedilink
        arrow-up
        0
        ·
        22 days ago

        I don’t understand it. Every time I see something about a rebase it’s some purist telling me it’s “cleaner”. Never got it to do what it says on the tin, and never hit a situation that I couldn’t solve using more straightforward tools like merge.

        • GissaMittJobb@lemmy.ml
          link
          fedilink
          arrow-up
          0
          ·
          22 days ago

          What’s your mental model for a Git commit, and a Git branch?

          Once I properly learned those two concepts, understanding rebases became a lot easier.

          I’ll try to explain it to the best of my abilities.

          • Think of a commit being a patch - a description of how to take a particular file from one state to another
          • A branch is a list of patches to be applied in order, from the point where the branch was created until the last commit on the branch

          When you rebase a particular branch, what you’re essentially doing is taking all of the commits that are currently on your branch, checking out the other branch, and then applying each of the patches in order on that new branch.

          A rebase can be cleanly applied if the premise for each commit has not changed when applied, but if the premise has changed, you get a conflict to be resolved before being able to continue the rebase.

          I mentally model a rebase a bit as a fast version of how it would look like to build the branch I was on, but on top of the branch I’m rebasing on.

          • Eiri@lemmy.ca
            link
            fedilink
            arrow-up
            0
            ·
            21 days ago

            That’s a good explanation of what it’s supposed to do. That was how I understood it as well.

            But anytime I’ve tried it, I’ve ended up with conflicts where there shouldn’t be (like, I already solved that conflict when I merged earlier) and/or completely undesirable results in the end (for instance, some of my changes are just NOT in the result).

            So I just gave up on the whole feature. Simpler to just merge the source branch into mine.

            • GissaMittJobb@lemmy.ml
              link
              fedilink
              arrow-up
              0
              ·
              21 days ago

              Depending on how structured your commits have been, it can either be very difficult to get a rebase through or a complete breeze. There are some features to make it easier - rerere being the main one I’m thinking about.

    • LedgeDrop@lemmy.zip
      link
      fedilink
      arrow-up
      0
      ·
      24 days ago

      … and force push.

      If you ever find yourself in a situation where rebase or a force push seems to be the solution, take a step back, clone your repo in a new directory and copy the changes into you’re new checkout - ‘cause you gon’ and screwed somethin’ up, son.

      • witness_me@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        23 days ago

        I rebase and force push daily. I like squashing all my commits, and our main branch moves quickly so I rebase off that often. Zero issues for me.

        • hayvan@feddit.nl
          link
          fedilink
          arrow-up
          0
          ·
          23 days ago

          Yeah, I hate it when my repo is a chain of merge commits. I want to see actual changes to the code, not branch management history.

        • smiletolerantly@awful.systems
          link
          fedilink
          arrow-up
          0
          ·
          23 days ago

          Same. And even if you were to fuck up, have people never heard of the reflog…?

          Every job I’ve worked at it’s been the expectation to regularly rebase your feature branch on main, to squash your commits (and then force push, obv), and for most projects to do rebase-merges of PRs rather than creating merge commits. Even the, uh, less gifted developers never had an issue with this.

          I think people just hear the meme about git being hard somewhere and then use that as an excuse to never learn.

          • Eiri@lemmy.ca
            link
            fedilink
            arrow-up
            0
            ·
            22 days ago

            Why would you want to squash? Feels weird to willingly give up history granularity…

            • smiletolerantly@awful.systems
              link
              fedilink
              arrow-up
              0
              ·
              22 days ago

              Because a commit should be an “indivisible” unit, in the sense that “should this be a separate commit?” equates to “would I ever want to revert just these changes?”.

              IDK about your commit histories, but if I’d leave everything in there, there’d be a ton of fixup commits just fixing spelling, satisfying the linter,…

              Also, changes requested by reviewers: those fixups almost always belong to the same commit, it makes no sense for them to be separate.

              And finally, I guess you do technically give up some granularity, but you gain an immense amount of readability of your commit history.