GameCharmer
GameCharmer

Reputation: 633

Reset a repo without breaking the repo

We currently have a repo with around 40,000 commits and it's starting to have issues with gitlab, specifically with failing the weekly health check. It's a pretty old repo that's been running for years.

Since starting a new project would result in a new project ID causing issues with our issue tracker, would it be possible / a reasonable idea to do something like the following:

  1. Create a new project, push the current repo into that project (just as a backup)
  2. Create a temp branch based on master
  3. Delete master, create new master branch
  4. merge --squash the temp branch back into the master branch

No one works directly on master and it's only used for deployment. When a MR is accepted, it gets squash merged into master, some files are updated, and a new tag is stamped with the next version id. All running processes use the tag as a checkout point instead of just the master branch.

In the end, would this do anything to help, or just mess things up?

Upvotes: 0

Views: 55

Answers (1)

orzechow
orzechow

Reputation: 1211

As suggested by Asif Kamran Malick, an orphan branch can help:

  • Checkout your old main/master
    git checkout master
  • Create a backup branch
    git checkout -b backup
  • Delete the old master branch (so we can use the same name)
    git branch -D master
  • Create a new master branch without any history
    git checkout --orphan master
  • Add your latest files / code to this new branch (in my quick test the checkout kept all files in the working dir)
    git commit --all -m "Add latest files in one fresh commit"
  • Push the new master to your Git server like Github/Gitlab/… (you might have to delete it first on the remote or force push if possible)

Still, this is a rather rough procedure, so make sure all collegues use the new master for new features (otherwise you'll merge in all the history again) and be ready to deal with hickups in the transition period.

Upvotes: 1

Related Questions