• Punkie@lemmy.world
    link
    fedilink
    arrow-up
    70
    ·
    8 months ago

    The thing is that for a majority of cases, this is all one needs to know about git for their job. Knowing git add, git -m commit “Change text”, git push, git branch, git checkout , is most of what a lone programmer does on their code.

    Where it gets complicated real fast is collaboration on the same branch. Merge conflicts, outdated pulls, “clever shortcuts,” hacks done by programmers who “kindof” know git at an advanced level, those who don’t understand “least surprise,” and those who cut and paste fixes from Stackexchange or ChatGPT. Plus who has admin access to “undo your changes” so all that work you did and pushed is erased and there’s no record of it anymore. And egos of programmers who refuse any changes you make for weird esoteric reasons. I had a programmer lead who rejected any and all code with comments “because I like clean code. If it’s not in the git log, it’s not a comment.” And his git comments were frustratingly vague and brief. “Fixed issue with ssl python libs,” or “Minor bugfixes.”

    • Ottomateeverything@lemmy.world
      link
      fedilink
      arrow-up
      50
      ·
      8 months ago

      I had a programmer lead who rejected any and all code with comments “because I like clean code. If it’s not in the git log, it’s not a comment.”

      Pretty sure I would quit on the spot. Clearly doesn’t understand “clean” code, nor how people are going to interface with code, or git for that matter. Even if you write a book for each commit, that would be so hard to track down relevant info.

      • mkwt@lemmy.world
        link
        fedilink
        arrow-up
        31
        ·
        8 months ago

        Yeah, I think that guy only got a superficial understanding of what Uncle Bob was saying.

        My policy as a tech lead is this: In an ideal world, you don’t need the comment because the names and the flow are good. But when you do need the comments, you usually really need those comments. Anything that’s surprising, unusual, or possibly difficult to understand gets comments. Because sometimes the world is not ideal, and we don’t have the time or energy to fully express our ideas clearly in code.

        My policy on SCM logs is that they should be geared more towards why this commit is going in, not what is being done. And what other tickets, stories, bugs it relates to.

        • PrettyFlyForAFatGuy@lemmy.ml
          link
          fedilink
          arrow-up
          20
          ·
          8 months ago

          Lead of a small team of scripters here. The “Why. Not What” is defo a good way of encouraging cleaner code.

          Had to request changes recently on a PR like this, big function with comments telling me what it was doing. When they resubmitted for review they had broken it down into smaller functions with good variable/function naming. following what was going on was much easier

          • AA5B@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            8 months ago

            Same strategy here, but recently found myself commenting on the “what”. There was a perfect built-in, but not really readable and I couldn’t figure out how to make it readable, so fine

        • bleistift2@feddit.de
          link
          fedilink
          English
          arrow-up
          6
          ·
          8 months ago

          But when you do need the comments, you usually really need those comments.

          It’s nice to see you sharing my experience. My code is either uncommented or very severely commented with comment-to-code ratios of 10:1 or more. I hate the files that are soo green… :(

        • AstridWipenaugh@lemmy.world
          link
          fedilink
          arrow-up
          5
          ·
          8 months ago

          We solve that problem using naming conventions. Branch names must start with the issue key (we use Jira). You don’t do anything in that branch that’s not part of that issue. If you do, you must prefix the commit message with the issue key that it goes with. The commit itself identifies what changed. The Jira issue provides all the backstory and links to any supporting materials (design docs, support tickets, etc). I have to do a lot of git archeology in my role, and this scheme regularly allows me to figure out why a code change was made years ago without ever talking to anyone.

          • AA5B@lemmy.world
            link
            fedilink
            arrow-up
            3
            ·
            8 months ago

            To be honest, when I ask a candidate about git, I’m looking for them to describe this workflow.

            Heck, I have a new person who I tasked with minor config change, just to make sure she knows how to use git in a professional environment

    • Ekky@sopuli.xyz
      link
      fedilink
      English
      arrow-up
      19
      arrow-down
      1
      ·
      8 months ago

      “Fixed issue with ssl python libs,” or “Minor bugfixes.”

      Red bird going "Hahaha, No!"

      In other news, never work more than one person on a branch (that’s why we have them). Make a new related issue with its own branch and rebase whenever necessary, and don’t even think about touching main or dev with anything but a properly reviewed and approved PR (in case they aren’t already protected), or I’ll find and report you to the same authority that handles all the failed sudo requests!

      Also, companies that disable rebasing are my bane. While you can absolutely do without, i much prefer to have less conflicts, cleaner branches and commits, easier method to pull in new changes from dev, overall better times for the reviewer, and the list goes on. Though, the intern rewriting multiple branches’ history which they have no business pushing to is also rather annoying.

    • Valmond@lemmy.mindoki.com
      link
      fedilink
      arrow-up
      9
      ·
      8 months ago

      Why does

      git rebase

      work sometimes?

      Yeah git can get quite complicated when there ate lots of people working on the same things.

      • mkwt@lemmy.world
        link
        fedilink
        arrow-up
        17
        ·
        8 months ago

        It’s not git that’s complicated. The work is complicated. git is just one of the tools that programmers use to manage the complexity.

        I also think that some people get too hung up on having a “clean” history, and trying to “fix” the history after it has already occurred. I usually have enough problems to worry about in the present, without also trying to worry about the past.

        • Wrench@lemmy.world
          link
          fedilink
          arrow-up
          7
          ·
          8 months ago

          I find the “clean history” argument so flawed.

          Sure, if you’re they type to micro commit, you can squash your branch and clean it up before merging. We don’t need a dozen “fixed tests” commits for context.

          But in practice, I have seen multiple teams with the policy of squash merging every branch with 0 exceptions. Even going so far as squash merging development branches to master, which then lumps 20 different changes into a single commit. Sure, you can always be a git archeologist, check out specific revisions, see the original commits, and dig down the history over and over, to get the original context of the specific change you’re looking into. But that’s way fucking more overhead than just looking at an unmanipulated history and seeing the parallel work going on, and get a clue on context at a glance at the network graph.

          • GissaMittJobb@lemmy.ml
            link
            fedilink
            arrow-up
            3
            ·
            8 months ago

            Using curated commits to optimize for pull request reviewability is highly underrated. Liberal use of interactive rebasing to ‘tell a story’, essentially.

          • andioop@programming.dev
            link
            fedilink
            English
            arrow-up
            2
            ·
            8 months ago

            you’re they type to micro commit

            Thanks for a much shorter and better way to explain this tendency of mine and why I rebase a lot, yoinking this phrase.

        • zqwzzle@lemmy.ca
          link
          fedilink
          English
          arrow-up
          5
          ·
          8 months ago

          I like to rebase on my feature branches before the PR because it’s a gift to my future self that resolves all the conflicts (if any) before my work goes in. I just find trying to figure out how those conflicts got resolved when there are a bunch of merges in more difficult if there’s a problem later. It’s easier to understand for me. YMMV, this does not work for everyone. Etc etc.

    • bleistift2@feddit.de
      link
      fedilink
      English
      arrow-up
      9
      ·
      8 months ago

      If it’s not in the git log, it’s not a comment.”

      This is so incredibly dumb, though I’m sure I don’t have to tell you this. That comment will be buried in the git log if anyone ever fixes a typo on that line.