Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading