Yeah learned this the hard way.

  • Eiri@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    23 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
        ·
        21 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
          ·
          21 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
      ·
      23 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.

        • 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
            ·
            21 days ago

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

            • smiletolerantly@awful.systems
              link
              fedilink
              arrow-up
              0
              ·
              21 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.

        • 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.

  • cmhe@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    23 days ago

    Isn’t it the exact opposite?

    I learned that you can never make a mistake if you aren’t using git, or any other way for having access to old versions.

    With git it is really easy to get back to an old version, or bisect commits to figure out what exact change was the mistake.

    The only way I understand this joke is more about not wanting to be caught making a mistake, because that is pretty easy. In other methods figuring out who did the mistake might be impossible.

    • fibojoly@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      23 days ago

      You’re confusing errors in your code, and errors while doing some git command you thought you knew. Lucky you, it’s clearly never happened to you because you don’t mess around with it.

      • cmhe@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        23 days ago

        Sure, I sometimes messed up with git, but a git reset , checkout, rebase or filter-branch (In the extreme cases) normally fixes it, but real issues are very rare. And I use git a lot… But only the CLI, maybe people have issues with GUIs?

          • EzTerry@lemmy.zip
            link
            fedilink
            English
            arrow-up
            0
            ·
            23 days ago

            Funny those are commands I avoid… They all have to do with editing history which I know there is a vocal group here that loves “clean” history but that isn’t what happened.

            sure merge full features so you can roll back a feature… And if something is really off I might start from a snapshot commit and cherry pick/merge a bunch in but usually history is histoy… If submitting to a public project I may make a new branch with the cleaned version but why edit in line. That is risking issues.

    • AeonFelis@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      23 days ago

      This is not about mistakes in the Git-managed code. This is about mistakes in the Git commands themselves. Anything that involves merging/rebasing/conflict resolution can potentially be botched. These mistakes are usually fixable, but:

      1. Fixing it requires some Git proficiency behind the level of the common Git user.
      2. If you don’t catch it in time, and only find the mistake when it’s deep in your layers of Git history - well, good luck.
      • LePoisson@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        23 days ago

        Went to tech elevator boot camp, was a decent experience even if I don’t find myself doing exactly what I was expecting to do. Life is that way though.

        Anyways, my first week I fucked some git stuff up so bad I became the go to guy when anyone had any git issues because I had to learn so much to undo my egregious error. I don’t remember now exactly what it was but it took some serious git magic to sort.

        Just saying that point 1 is very true. And yeah don’t make mistakes in git.

  • QuizzaciousOtter@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    23 days ago
    1. Use git for any code you write. Yes, even a simple script.
    2. Commit and push often. More often than you think is reasonable. You can always rebase / fixup / squash / edit but you can’t recover what you didn’t commit.
    3. ???
    4. Profit.

    Seriously, once you commited something to the repo it’s hard to lose it. Unless you delete .git. But a this point frequent pushing has your back.

    I know git can be hard to grasp in the beginning. It was hard for me too. I highly encourage everyone to put in the effort to understand it. But if you don’t want to do that right now just use it. Just commit and push. It will pay off.

    • Rooster326@programming.dev
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      23 days ago
      1. (3) Get annoyed by constantly increasing Code Coverage Requirements on untestable (often legacy) code. Even afding comments requires code coverage go up! Line must always go up!
      2. Change step 2 to “Commit and push ONLY when absolutely necessary. Because adding comments often requires a rewrite of untestable code.”
      3. Go back to Step 2 and wait for a major bug.
      • fibojoly@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        23 days ago

        Our company “architects” decided we needed 80% coverage minimum. On a mostly .Net 4.8 codebase. Hundreds of programs used in prod, with barely any tests in sight.
        It’s a fucking nightmare.

        • Metju@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          22 days ago

          Ah, the classical “just introduce tests in a legacy codebase”, what can go wrong?

          My condolences, it’s always a BITCH to handle

          • fibojoly@sh.itjust.works
            link
            fedilink
            arrow-up
            0
            ·
            19 days ago

            Fixing that bug you just found in prod : half a day. Adding enough tests so the app is now at 80% coverage : a whole fucking week. My student colleague was not impressed. I was like “yup, that’s what jobs are like”.

      • ExperiencedWinter@lemmy.world
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        23 days ago

        Why would you care about code coverage requirements on a branch that is currently in development? My work in progress commits might not build because they don’t even compile, let alone have passing tests. The only time I care about the build passing and meeting requirements is when I’m ready to create the pull request.

        Also code coverage is a useless metric, but that’s a different story.

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    0
    ·
    24 days ago

    I’ve had juniors who didn’t believe this, so just to say it: If you know what you’re doing, practically any Git problem is recoverable.

    The one major exception is if you delete your local changes before committing them.

    • sorter_plainview@lemmy.today
      link
      fedilink
      arrow-up
      0
      ·
      24 days ago

      Yeah.But many of them are extremely annoying. Specifically screwing up rebase. It is recoverable, but very annoying.

      That said I have seen juniors make two other common mistakes.

      1. Pushing your commit without fetching
      2. Continuing on a branch even after it was merged.

      I’m fed up with these two. Yesterday I had to cherry-pick to solve a combination of these two.

      • psycotica0@lemmy.ca
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        23 days ago

        Maybe I’m just a wizard, or I don’t know what y’all are talking about, but rebases aren’t special. If you use git reflog it just tells you where you used to be before the rebase. You don’t have to fix anything, git is append only. See where the rebase started in reflog, it’ll say rebase in the log line, then git reset --hard THAT_HASH

        Pushing without fetching should be an error. So either they got the error, didn’t think about it, and then force pushed, or someone taught them to just always force push. In either case the problem is the force part, the tool is built to prevent this by default.

        Continuing after merge should be pretty easy? I’d assume rebase just does it? Unless the merge was a squash merge or rebase merge. Then yeah, slightly annoying, but still mostly git rebase -i and then delete lines look like they were already merged?

        • sorter_plainview@lemmy.today
          link
          fedilink
          arrow-up
          0
          ·
          23 days ago

          See all this is fine for someone with good experience in git. They know how to solve the screw up. But wih junior devs, who don’t know much about it, they will just get confused and stuck. And one of the senior has to involve and help them solve. This is just annoying because these can be avoided very easily. Until they understand the pattern of how everyone operates with git, it just creates issues.

          To me first time causing this issue is completely fine. I will personally sit with them and explain then what went wrong and how to recover. Most of them will repeat it again, act clueless and talk like they are seeing this for the first time in their life. That is the difficult part to me.

          May be I’m just old school, and a grumpy old person, even though I’m not that aged.

          • zalgotext@sh.itjust.works
            link
            fedilink
            arrow-up
            0
            ·
            23 days ago

            Sounds like the onboarding process needs to have a step in it that says “here’s a link to a git tutorial, read this and get familiar with using git, as it’s an integral tool that you will use every single day on the job”. Bonus points for providing a sample repo that juniors can use to mess around with git, extra bonus points for including steps in the onboarding materials for the juniors to set up their own repos to play around with.

  • kibiz0r@midwest.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    24 days ago

    Git repository operations are (almost?) always recoverable. git reflog is your friend.

    The filesystem operations are another story. Handle with care.

      • kibiz0r@midwest.social
        link
        fedilink
        English
        arrow-up
        0
        ·
        24 days ago

        Think of it like your browser history but for Git. It’s a list of the SHAs related to your recent operations.

        And because Git is a content-addressable data store, a SHA is basically like a URL. Even if a branch no longer exists, if you know the SHA it pointed to then you can still check out the exact contents of that branch. The reflog helps you find that.

        • theneverfox@pawb.social
          link
          fedilink
          English
          arrow-up
          0
          ·
          23 days ago

          Goddamit… It’s ref log, not re flog. I thought this was related to blame and never touched it lmao

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

            Re flog is when your devs don’t follow your guides and mess uo git history again.

            • theneverfox@pawb.social
              link
              fedilink
              English
              arrow-up
              0
              ·
              23 days ago

              I legit thought it was to publicly call out a user to be (metaphorically) flogged

              And while it’s not how I do things, I totally understand the impulse. Tell me that doesn’t sound like something that could exist

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

                Knowing that git blame exists, and Linus in general, indeed a git flog isn’t that improbable.