• Margot Robbie@lemm.ee
    link
    fedilink
    arrow-up
    4
    ·
    6 months ago

    I think this is a fake quote that somebody made up for an Internet comedy bit, since it seems unlikely for Hollywood actress Sydney Sweeney to have such uncharacteristically strong opinion on software version control, of all things.

    Because she of all people would know that there isn’t anything wrong with using git merge, and it ultimately comes down to personal preference to what you are used to.

      • CmdrKeen@lemmy.today
        link
        fedilink
        arrow-up
        3
        ·
        6 months ago

        No doubt. git rebase is like a very sharp knife. In the right hands, it can accomplish great things, but in the wrong hands, it can also spell disaster.

        As someone who HAS used it a fair amount, I generally don’t even recommend it to people unless they’re already VERY comfortable with the rest of git and ideally have some sense of how it works internally.

        • expr@programming.dev
          link
          fedilink
          arrow-up
          0
          ·
          6 months ago

          Yeah it is something people should take time to learn. I do think its “dangers” are pretty overstated, though, especially if you always do git rebase --interactive, since if anything goes wrong, you can easily get out with git rebase --abort.

          In general there’s a pretty weird fear that you can fuck up git to the point at which you can’t recover. Basically the only time that’s really actually true is if you somehow lose uncommitted work in your working tree. But if you’ve actually committed everything (and you should always commit everything before trying any destructive operations), you can pretty much always get back to where you were. Commits are never actually lost.

          • thanks_shakey_snake@lemmy.ca
            link
            fedilink
            arrow-up
            2
            ·
            6 months ago

            You can get in some pretty serious messes, though. Any workflow that involves force-pushing or rebasing has the potential for data loss… Either in a literally destructive way, or in a “Seriously my keys must be somewhere but I have no idea where” kind of way.

            When most people talk about rebase (for example) being reversible, what they’re usually saying is “you can always reverse the operation in the reflog.” Well yes, but the reflog is local, so if Alice messes something up with her rebase-force-push and realizes she destroyed some of Bob’s changes, Alice can’t recover Bob’s changes from her machine-- She needs to collaborate with Bob to recover them.

            • expr@programming.dev
              link
              fedilink
              arrow-up
              1
              ·
              6 months ago

              Pretty much everything that can act as a git remote (GitHub, gitlab, etc.) records the activity on a branch and makes it easy to see what the commit sha was before a force push.

              But it’s a pretty moot point since no one that argues in favor of rebasing is suggesting you use it on shared branches. That’s not what it’s for. It’s for your own feature branches as you work, in which case there is indeed very little risk of any kind of loss.

              • thanks_shakey_snake@lemmy.ca
                link
                fedilink
                arrow-up
                2
                ·
                6 months ago

                Ah, you’ve never worked somewhere where people regularly rebase and force-push to master. Lucky :)

                I have no issue with rebasing on a local branch that no other repository knows about yet. I think that’s great. As soon as the code leaves local though, things proceed at least to “exercise caution.” If the branch is actively shared (like master, or a release branch if that’s a thing, or a branch where people are collaborating), IMO rebasing is more of a footgun than it’s worth.

                You can mitigate that with good processes and well-informed engineers, but that’s kinda true of all sorts of dubious ideas.

                • expr@programming.dev
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  6 months ago

                  Pushing to master in general is disabled by policy on the forge itself at every place I’ve worked. That’s pretty standard practice. There’s no good reason to leave the ability to push to master on.

                  There’s no reason to avoid force pushing a rebased version of your local feature branch to the remote version of your feature branch, since no one else should be touching that branch. I literally do this at least once a day, sometimes more. It’s a good practice that empowers you to craft a high-quality set of commits before merging into master. Doing this avoids the countless garbage fix typo commits (and spurious merge commits) that you’d have otherwise, making both reviews easier and giving you a higher-quality, more useful history after merge.

              • aubeynarf@lemmynsfw.com
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                4 months ago

                If “we work in a way that only one person can commit to a feature”, you may be missing the point of collaborative distributed development.

                • expr@programming.dev
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  5 months ago

                  No, you divide work so that the majority of it can be done in isolation and in parallel. Testing components together, if necessary, is done on integration branches as needed (which you don’t rebase, of course). Branches and MRs should be small and short-lived with merges into master happening frequently. Collaboration largely occurs through developers frequently branching off a shared main branch that gets continuously updated.

                  Trunk-based development is the industry-standard practice at this point, and for good reason. It’s friendlier for CI/CD and devops, allows changes to be tested in isolation before merging, and so on.

  • tengkuizdihar@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    Please for the love of god don’t use merge, especially in a crowded repository. Don’t be me and suffer the consequences. I mistakenly mention every person with a commit between the time I created the branch until current master.

      • tengkuizdihar@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        6 months ago

        really? how come? I thought they are mentioned because of the diffs if compared to master, which merge basically just… merge on top of my branch (?)

        • Atemu@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          6 months ago

          They were mentioned because a file they are the code owner of was modified in the PR.

          The modifications came from another branch which you accidentally(?) merged into yours. The problem is that those commits weren’t in master yet, so GH considers them to be part of the changeset of your branch. If they were in master already, GH would only consider the merge commit itself part of the change set and it does not contain any changes itself (unless you resolved a conflict).

          If you had rebased atop of the other branch, you would have still had the commits of the other branch in your changeset; it’d be as if you tried to merge the other branch into master + your changes.

          • Bourff@lemmy.world
            link
            fedilink
            arrow-up
            0
            arrow-down
            1
            ·
            edit-2
            6 months ago

            Just for the record, I think you’re conflating git and GitHub. They are not the same thing, even if GH would like you to think so.

  • Croquette@sh.itjust.works
    link
    fedilink
    arrow-up
    0
    ·
    6 months ago

    I know this is a meme post, but can someone succinctly explain rebase vs merge?

    I am an amateur trying to learn my tool.

    • jaemo@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      Merge keeps the original timeline. Your commits go in along with anything else that happened relative to the branch you based your work off (probably main). This generates a merge commit.

      Rebase will replay all the commits that happened while you were doing your work before your commits happen, and then put yours at the HEAD, so that they are the most recent commits. You have to mitigate any conflicts that impact the same files as these commits are replayed, if any conflicts arise. These are resolved the same way any merge conflict is. There is no frivolous merge commit in this scenario.

      TlDR; End result, everything that happened to the branch minus your work, happens. Then your stuff happens after. Much tidy and clean.

      • Croquette@sh.itjust.works
        link
        fedilink
        arrow-up
        0
        ·
        6 months ago

        Thanks for the explanation. It makes sense. To my untrained eyes, it feels like both merge and rebase have their use. I will try to keep that in mind.

        • aubeynarf@lemmynsfw.com
          link
          fedilink
          arrow-up
          1
          ·
          5 months ago

          Never use rebase for any branch that has left your machine (been pushed) and which another entity may have a local copy of (especially if that entity may have committed edits to it).

        • JackbyDev@programming.dev
          link
          fedilink
          English
          arrow-up
          0
          ·
          6 months ago

          Yes. They do. A lot of people will use vacuous terms like “clean history” when arguing for one over the other. In my opinion, most repositories have larger problems than rebase versus merge. Like commit messages.

          Also, remember, even if your team/repository prefers merges over rebases for getting changes into the main branch, that doesn’t mean you shouldn’t be using rebase locally for various things.

          • Croquette@sh.itjust.works
            link
            fedilink
            arrow-up
            0
            ·
            6 months ago

            How would rebasing my own branch work? Do I rebase the main into my branch, or make a copy of the main branch and then rebase? I have trouble grasping how that would work.

            • JackbyDev@programming.dev
              link
              fedilink
              English
              arrow-up
              1
              ·
              6 months ago

              You’re still rebasing your branch onto main (or whatever you originally branched it off of), but you aren’t then doing a fast forward merge of main to your branch.

              The terminology gets weird. When people say “merge versus rebase” they really mean it in the context of brining changes into main. You (or the remote repository) cannot do this without a merge. People usually mean “merge commit versus rebase with fast forward merge”

              • jaemo@sh.itjust.works
                link
                fedilink
                arrow-up
                0
                ·
                6 months ago

                https://gitmoji.dev/

                Quasi parallel reply to your other post, this would kind of echo the want for a capital letter at the start of the commit message. Icon indicates overall topic nature of commits.

                Lets say I am adding a database migration and my commit is the migration file and the schema. My commit message might be:

                     🗃️ Add notes to Users table
                

                So anyone looking at the eventual pr will see the icon and know that this bunch of work will affect db without all that tedious “reading the code” part of the review, or for team members who didn’t participate in reviews.

                I was initially hesitant to adopt it but I have very reasonable, younger team mates for whom emojis are part of the standard vocabulary. I gradually came to appreciate and value the ability to convey more context in my commits this way. I’m still guilty of the occasionally overusing:

                   ♻️ Fix the thing
                

                type messages when I’m lazy; doesn’t fix that bad habit, but I’m generally much happier reading mine or someone else’s PR commit summary with this extra bit of context added.

                • Deebster@programming.dev
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  6 months ago

                  I looked at it and there’s a lot of them!

                  I see things like adding dependencies but I would add the dependency along with the code that’s using it so I have that context. Is the Gitmoji way to break your commits up so that it matches a single category?

    • letsgo@lemm.ee
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      6 months ago

      Merge gives an accurate view of the history but tends to be “cluttered” with multiple lines and merge commits. Rebase cleans that up and gives you a simple A->B->C view.

      Personally I prefer merge because when I’m tracking down a bug and narrow it down to a specific commit, I get to see what change was made in what context. With rebase commits that change is in there, but it’s out of context and cluttered up with zillions of other changes from the inherent merges and squashes that are included in that commit, making it harder to see what was changed and why. The same cluttered history is still in there but it’s included in the commits instead of existing separately outside the commits.

      I honestly can’t see the point of a rebased A->B->C history because (a) it’s inaccurate and (b) it makes debugging harder. Maybe I’m missing some major benefit? I’m willing to learn.

  • Cyborganism@lemmy.ca
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    6 months ago

    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.

    • TechNom (nobody)@programming.dev
      link
      fedilink
      English
      arrow-up
      0
      ·
      6 months ago

      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.

      • xigoi@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        6 months ago

        Why would you want to edit your commit history? When I need to look at it for some reason, I want to see what actually happened, not a fictional story.

      • AggressivelyPassive@feddit.de
        link
        fedilink
        arrow-up
        1
        ·
        6 months ago

        Honestly, I’m pretty sure 99.9% of git users never really bother with the git history in any way that would be hindered by merging.

        Git has a ton of powerful features, but for most projects they don’t matter at all. You want a distributed consensus, that’s it. Bothering yourself with all those advanced features and trying to learn some esoteric commands is frankly just overhead. Yes, you can solve great problems with them, but these problems almost never occur, and if they do, using the stupid tools is faster overall.

        • Chamomile 🐑@furry.engineer
          link
          fedilink
          arrow-up
          0
          ·
          edit-2
          6 months ago

          @agressivelyPassive @technom That’s a self-fulfilling prophecy, IMO. Well-structured commit histories with clear descriptions can be a godsend for spelunking through old code and trying to work out why a change was made. That is the actual point, after all - the Linux kernel project, which is what git was originally built to manage, is fastidious about this. Most projects don’t need that level of hygiene, but they can still benefit from taking lessons from it.

          To that end, sure, git can be arcane at the best of times and a lot of the tools aren’t strictly necessary, but they’re very useful for managing that history.

          • AggressivelyPassive@feddit.de
            link
            fedilink
            arrow-up
            0
            ·
            6 months ago

            I’d still argue, that the overhead is not worth it most of the time.

            Linux is one of the largest single pieces of software in existence, of course it has different needs than the standard business crap the vast majority of us develop.

            To keep your analogy: not every room is an operating room, you might have some theoretical advantages from keeping your kitchen as clean as an OR, but it’s probably not worth the hassle.

            • zalgotext@sh.itjust.works
              link
              fedilink
              arrow-up
              0
              ·
              6 months ago

              To keep your analogy, most people’s git histories, when using a merge-based workflow, is the equivalent of never cleaning the kitchen, ever.

              • AggressivelyPassive@feddit.de
                link
                fedilink
                arrow-up
                0
                ·
                6 months ago

                No, it’s not. And you know that.

                Seriously, ask yourself, how often did the need arise to look into old commits and if it did, wasn’t the underlying issue caused by the processes around it? I’ve been in the industry for a few years now and I can literally count on one hand how often I had to actually look at commit history for more than maybe 10 commits back. And I spend maybe 10min per year on that on average, if at all.

                I honestly don’t see a use case that would justify the overhead. It’s always just “but what if X, then you’d save hours!” But X never happens or X is caused by a fucked up process somewhere else and git is just the hammer to nail down every problem.

                • zalgotext@sh.itjust.works
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  6 months ago

                  Seriously, ask yourself, how often did the need arise to look into old commits

                  Literally every single day. I have a git alias that prints out the commit graph for my repositories, and by looking at that I can instantly see what tasks my coworkers are working on, what their progress is, and what their work is based on. It’s way more useful than any stand-up meeting I’ve ever attended.

                  I’ve been in the industry for a few years now and I can literally count on one hand how often I had to actually look at commit history for more than maybe 10 commits back.

                  I’ve been in the industry for nearly 15 years, but I can say that the last 3 years have been my most productive, and I attribute a lot of that to the fact that I’m on a team that cares about git history, knows how to use it, and keeps it readable. Like other people have been saying, this is a self fulfilling prophecy - most people don’t care to keep their git history readable, so they’ve only ever seen unreadable git histories, and so they think git history is useless.

                  I honestly don’t see a use case that would justify the overhead.

                  What overhead? The learning curve on rebasing isn’t that much steeper than that of merging or just using git itself. Take an hour to read the git docs, watch a tutorial or two, and you’re good to go. Understand that people actually read your commit messages and take 15 extra seconds to make them actually useful. Take an extra minute before opening an MR to rebase your personal branches interactively and squash down the “fixed a typo” and “ran isort” commits into something that’s actually useful. In the long run this saves time by making your code more easily reviewable, and giving reviewers useful context around your changes.

                  It’s always just “but what if X, then you’d save hours!” But X never happens or X is caused by a fucked up process somewhere else and git is just the hammer to nail down every problem.

                  No, having a clean, readable git history literally saves my team hours. I haven’t had to manually write or edit a changelog in three years because we generate it automatically from our commit messages. I haven’t had to think about a version number in three years because they’re automatically calculated from our commit messages. Those are the types of things teams sink weeks into, time absolutely wasted spent arguing over whether this thing or that is a patch bump or a minor bump, and no one can say for sure without looking at diffs or spinning up multiple versions of the code and poking it manually, because the git log is a tangled mess of spaghetti with meatballs made of messages like “finally fixed the thing” and “please just work dammit”. My team can tell you those things instantly just by looking at the git log. Because we care about history, and we keep it clean and useable.

                • thanks_shakey_snake@lemmy.ca
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  6 months ago

                  I gotta say, I was with you for most of this thread, but looking through old commits is definitely something that I do on a regular basis… Like not even just because of problems, but because that’s part of how I figure out what’s going on.

                  The whole reason I keep my git history clean and my commit messages thoughtful is so that future-me (or future-someone-else) will have an easier time walking through it later, because that happens all the time.

                  I’ll still almost always choose merge instead of rebase, but not because I don’t care about the git history-- quite the opposite, it’s really important to me in a very practical way.

        • TechNom (nobody)@programming.dev
          link
          fedilink
          English
          arrow-up
          0
          arrow-down
          1
          ·
          6 months ago

          Only users who don’t know rebasing and the advantages of a crafted history make statements like this. There are several projects that depend on clean commit history. You need it for conventional commit tools (like commitzen), pre-commit hook tools, git blame, git bisect, etc.

          • AggressivelyPassive@feddit.de
            link
            fedilink
            arrow-up
            0
            arrow-down
            1
            ·
            6 months ago

            Uuuh, am I no true Scotsman?

            Counter argument: why do you keep fucking up so bad you need these tools? Only users who are bad at programming need these. Makes about as much sense as your accusation.

            You keep iterating the same arguments as the rest here, and I still adhere to my statement above: hardly anybody needs those tools. I literally never used pre-commit hooks or bisect in any semi-professional context. And I don’t know a single project that uses them. And before you counter with another “well u stoopid then” comment: the projects I’ve been working on were with pretty reputable companies and handled literally billions of Euros every year. I can honestly say, that pretty much everyone living in Germany had his/her data pushed through code that I wrote.

    • magic_lobster_party@kbin.run
      link
      fedilink
      arrow-up
      0
      ·
      6 months ago

      How others are keeping their branches up to date is their problem. If you use Gitlab you can set up squash policy for merge requests. All the abomination they’ve caused in their branch will turn into one nice commit to the main branch.

      • expr@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        6 months ago

        I don’t want squashed commits. It makes git tools worse (git bisect, git cherry-pick, etc.) and I work very hard to craft a meaningful set of commits for my work and I don’t want to throw all of that away.

        But yeah, I don’t actually give a shit what they are doing on their branches. I regularly rebase onto master anyway.