Yeah learned this the hard way.

  • marcos@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    28 days ago

    You know… A version control system… That class of software that makes it possible for you to recover from any error you commit.

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

  • kibiz0r@midwest.social
    link
    fedilink
    English
    arrow-up
    0
    ·
    28 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
        ·
        28 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.