Home > Mobile >  Re-open master from a previous commit
Re-open master from a previous commit

Time:09-16

I have the following master branch structure:

WrongCommit1-->WrongCommit2-->WrongCommit3       master
              /
             /
GoodCommit---                                    master

I'd like to "re-start" the master branch from the GoodCommit, do some changes and forget the Head ending with WrongCommit3.

How is it possible to do in git?

CodePudding user response:

I presume GoodCommit is for you a SHA-1

git checkout master
git reset --hard <GoodCommit>
git push --force origin master

Optionally, you can remove the wrong commits from the history

git gc

more: how to git reset to head

CodePudding user response:

Not sure if this is the 'proper' way to do it, but it works for me:

  1. Revert back to GoodCommit using git revert <id> or with some GUI application like GitHub Desktop.
  2. Force push into master with git push --force origin master, or again with that application.

This sets your machine back to the GoodCommit, then forcibly overrides any chagnes and places it into the top of master.

  •  Tags:  
  • git
  • Related