How to revert back to previous commit and make it the default branch Ignoring any further commits

Advertisements

I want to revert back to a previous commit and make it my new default branch in a clean way. Ignoring any future commits.

this what I did:

git checkout <commit-hash>
git branch new-main

How to make the new-main branch the default branch and make the development continue from there?

>Solution :

IF (not 100% sure that’s what you’re asking but it sounds like it) you want your main branch to be set to the same commit new-main is currently at, the typical course of action would be (from a clean working tree, or else your uncommitted changes will be lost)

$ git checkout main
$ git reset --hard new-main

This is for your local repo.

Then IF your remote main is still pointing at the old (unwanted) commit, you won’t be able to push without --force, so be sure to check with your team if this is okay in your context.

Leave a ReplyCancel reply