I’m thinking on writing some tutorial on de-sloppifying some open-source projects, with I’m likely ending up at least starting some of them.

  • 0xDEADBEEFCAFE@programming.dev
    link
    fedilink
    English
    arrow-up
    7
    ·
    3 days ago

    A shorter example:

    git clone https://codeberg.org/yourname/yournewrepo
    cd yournewrepo
    git reset --hard abcdef1 # commit that you want to reset to
    git push --force origin
    

    Note that instead of abcdef1 in git reset you can also use the regular expression syntax. So if the commit was named Last release before unwanted changes you would say git reset --hard ':/Last release before unwanted changes'.

  • zener_diode@feddit.org
    link
    fedilink
    arrow-up
    7
    arrow-down
    1
    ·
    3 days ago

    You should be able to just fork it normally, then reset (or is it revert?) to the commit you want.

  • bignose@programming.dev
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    3 days ago

    It may depend where the project is and what you want to bring with you.

    If you’re asking solely about the Git repository: you need to find exactly which commit is the latest one you want to bring, and specify that commit identifier (the hash of that commit) as the “starting point” when you create a new branch.

    git branch […] <branch-name> [<start-point>]

    https://git-scm.com/docs/git-branch

    So, clone the repository locally however you need to do that. Then, in your local repository, modify what the branches point to:

    e.g. If you determined the latest commit you want to bring, has commit identifier “deadbeefbad1dea”, you can create the branch named “before-the-slop”:

    git branch before-the-slop deadbeefbad1dea

    Now the new branch “before-the-slop” has all the commits up to that, and no further. That’s what you’ll base your fork on.

    git branch before-the-slop

    git rev-parse HEAD # → deadbeefbad1dea

    Then rename the old “main” or whatever branch, to something like “sloppified-project-main” that gets it out of the way; rename your “before-the-slop” branch to “main”; and set “main” as the default branch in your repository.

    git branch --move main sloppified-project-main

    git branch --move before-the-slop main

    git config set --local init.defaultBranch main

    Some time later, when you’ve confirmed your repository is how you like it, delete the “sloppified-project-main” branch:

    git branch --delete sloppified-project-main

    and breathe easy.

      • FizzyOrange@programming.dev
        link
        fedilink
        arrow-up
        3
        arrow-down
        3
        ·
        2 days ago

        I mean… It legit can though. You may hate AI for coding but I don’t see why you wouldn’t use it for questions like this. Do you not think it could answer this question?

        • HubertManne@piefed.social
          link
          fedilink
          English
          arrow-up
          3
          arrow-down
          2
          ·
          2 days ago

          why ask ai for something like this. You know you could just ask a forum of people interested in the topic. I don’t get why people who want to participate in a forum then feel people should not bring up things to discuss in a forum for the life of me.

          • FizzyOrange@programming.dev
            link
            fedilink
            arrow-up
            1
            ·
            2 days ago

            Because it will give you an answer instantly? There are plenty of other things you can bring to forums - news, projects, etc.

            • HubertManne@piefed.social
              link
              fedilink
              English
              arrow-up
              2
              ·
              2 days ago

              and you could try ai on all those other things and you can just talk in a forum for this. Some people don’t really use ai. Heck I mostly just use it to sorta evaluate it. I have high hopes for future open source local uses that are more to my liking but what we have now is something I take with a grain of salt.

  • stembolts@programming.dev
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    2 days ago

    Reading your comment literally, that you want a step by step description.

    Assuming you are starting a brand new repo.

    Clone.
    Identify commit from which to fork.
    Checkout commit by hash.
    Delete .git. get reset --hard some-hash
    git init
    git add, excluding whatever for whatever reason.
    git commit -m “Init fork.”

    That’s what makes sense to me thinking through it. No idea if it works that way, never tried it. But that is what I would try first.

    Lemme know if I fucked up anything.

    Now my own questions, the other comments seem to be maintaining a reference to the original repo, is that what is going on?

    • expr@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      2 days ago

      There’s no sense in deleting a project’s history before the fork, which is what that would do.

      It’s really quite simple:

      git reset --hard <some-commit-hash>. This will set HEAD to that commit, along with the contents of the working directory. You are the free to push to whichever git forge you are hosting on.

      • stembolts@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        2 days ago

        That makes sense. I’ll amend my comment.

        Couldn’t you also git checkout -b hash for the same result, then fork with the new branch?

        Or are the results different in some way?

        • expr@programming.dev
          link
          fedilink
          arrow-up
          2
          ·
          2 days ago

          Sure that works too, though you would likely need to configure your git forge to treat that new branch as the master branch. A branch is ultimately just a pointer to a particular commit, though usually git forges treat one particular branch as “special” (it’s the default branch used for clones, and typically disallows direct pushes). This is usually the master or main branch. So my git reset suggestion was intended to reset whatever the default branch of the upstream repo was (probably master).