Here is a quick guide on how to reset your repository, main branch and live website to a previously proven working version without loosing changes since then.
First the CLI stuff:
cd your-website
git checkout main
git checkout -b lastworking hashoflastworkingversion
git branch -m nonworkingchanges
git checkout lastworking
git branch -m main
git push origin --force
- Step 1: go to your website folder
- Step 2: check out the main/master branch (that’s the branch with the last changes that are not working)
- Step 3: create a branch
lastworking
with the hash of the last change that worked on your site - Step 4: move the main branch to
nonworkingchanges
or another passive agressive branch name - Step 5: checkout
lastworking
- Step 6: set
lastworking
tomain
or master (we call them main these days because all branches matter) - Step 7: send the changes to the original repository (forcing the update like an, ehm, master)
- Step 8 (not in the CLI output): pray that your upstream hoster can rebuild a working site (specifically on Netlify cancel all running deploys and “Clear cache and deploy” the site new)
After this you have two branches: main
that contains the last known working version and nonworkingchanges
that is x commits ahead of main, but not working.
Never change a running system. (Even if new features sound great.)