1

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.

CMSCSS
  • 2,076
  • 9
  • 28
  • 49
  • If I can see the correct commit in Tower's history, can I reset to that commit? Unfortunately this all happened when trying to pull the latest changes so after reverting, I pushed/pulled thinking the remote changes (correct) would come down). This all means that the repo on the remote is now in the same broken state. – CMSCSS Dec 16 '14 at 06:05
  • If I right-click the correct commit and choose "Reset HEAD to..." there's an option to keep changes but I don't understand the explanation - based on git search results (for the command line version) I suspect I should be looking for ```reset --hard``` but I don't see that option in Tower. – CMSCSS Dec 16 '14 at 06:13
  • "Select the "Keep Changes" option if you want all changes from rolled back revisions to be kept in your working directory." What are 'rolled back revisions' and how to you work out if you have any? – CMSCSS Dec 16 '14 at 06:18
  • In Terminal I ran ```git reset --hard 94e8d...``` and while the terminal states that the HEAD is now at the previous commit nothing has changed in Tower (have restarted Tower as well) - except that Tower now says there are two commits to pull from github. I'm loathe to pull these commits incase it ruins the repo (again). I guess I don't understand why my previous revert commit is still showing - didn't I just reset to the previous commit? – CMSCSS Dec 16 '14 at 06:35
  • Tower is reporting that the head is at the previous commit but I thought it would just reset everything to this commit - not just move the head. The newer (incorrect) commit is still showing above the correct commit that's set to the head. – CMSCSS Dec 16 '14 at 06:42
  • So had to pull the changes from the commit before I could push and this pulled down the previous pushed changes - which has returned the repo to it's previous incorrect state. Have now turned the correct commit into a branch and am back to replacing master with this branch but am scared to death! But I can't get any work done until this is solved so am kind of stuck. – CMSCSS Dec 16 '14 at 06:51

1 Answers1

4

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.

CMSCSS
  • 2,076
  • 9
  • 28
  • 49