Git Tower - how to overwrite master with a previous commit

1k views Asked by At

Somehow I've created a git mess where the latest commit is wrong but the previous commit is right.

I tried to revert to the previous commit in Tower (right click) but that created some kind of merge which didn't fix the issue and now things look messier than ever.

I've created a new branch from the commit I know to be correct and have tested it and everything looks great.

Question: is it possible to simply replace the master branch with this new branch?

I obviously want to avoid creating an even bigger mess so would like to know if this is possible or if this is even a good idea? All the search results look scary as I don't fully understand what they're going to do.

For the life of me I don't know what went wrong as the repo only contained one branch.

1

There are 1 answers

1
CMSCSS On BEST ANSWER

OK, so if you you'd like to replace master with a commit in Tower/Github, here's what worked for me:

  1. Click on the master branch and find the commit you're going to use to replace master
  2. Right click and choose "Create new branch from ..."
  3. Name the branch 'master-new'
  4. Publish this branch to github
  5. Login to github and click the settings button to administer the repo
  6. Make sure 'Options' is selected in the left subnav
  7. Under the repository name field, find the 'Defaualt' dropdown menu
  8. Change the default to 'master-new'
  9. We do this becauase you can't delete the branch Github uses as the default
  10. Back in Tower, 'master-new' should be checked out - if not, checkout master-new
  11. Delete your local 'master' branch
  12. Now go to the remotes/origin area in the left sidebar
  13. Right click the master branch and choose 'Delete origin/master'
  14. Right click your local 'master-new' branch and rename it to 'master'
  15. Do the exact same thing to the remote 'master-new' branch

Now you've migrated master over to a new branch locally and on the remote.