Yeah learned this the hard way.

  • Ephera@lemmy.ml
    link
    fedilink
    English
    arrow-up
    38
    ·
    1 month 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.

  • QuizzaciousOtter@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    12
    ·
    edit-2
    1 month 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
      2
      ·
      edit-2
      1 month 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.
      • QuizzaciousOtter@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        1
        ·
        1 month ago

        3 is not related to using git in any way. I’m not really sure what you mean in 4. I didn’t mean making a lot of changes, I meant that you should not wait with committing until you have a finished feature / fix / whatever. Commit after each refactor, commit after adding a new testable unit. It’s always better to have more checkpoints. If your team does code review, they will appreciate atomic commits too.

  • kibiz0r@midwest.social
    link
    fedilink
    English
    arrow-up
    10
    ·
    1 month ago

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

    The filesystem operations are another story. Handle with care.

  • ranzispa@mander.xyz
    link
    fedilink
    arrow-up
    1
    ·
    19 days ago

    The main reason I use git is it allows me to make mistakes without hard consequences. Any fuckup is just one reset away from being fixed. I like to: I have to fix this thing. While attempting to fix it I discover there is another thing that needs fixing on which everything revolves. I fix the second thing and commit. I’m now free to fuck around the code all I want and I’m sure I won’t lose that fix.

    For this I really like to use --fixup when I find out the change was not completely right or does not fit well with some other changes I need to do. I really like git absorb which automates this a bit.