Search code examples
githerokugit-reset

How to revert/reset local master to HEAD?


I'm trying to push a older commit to heroku/master, but if I'm not mistaken git push pushes the local master to the remote repo. So I'm trying to get my local master to match my HEAD.

I'm trying to do it without losing the commits I made so I maybe could go back to them whenever I need. enter image description here

Things I've tried:

# this only set my HEAD on the wanted commit.
$ git reset --hard HEAD
$ git reset --hard 055c700

# this made a new branch called HEAD instead of my actual HEAD, which was a pain to delete afterwards 
$ git checkout -B "HEAD" "master"

Solution

  • The easiest way to do this is:

    1. Point your HEAD to your master first $ git checkout master
    2. Make a copy of the branch $ git checkout -b new_master
    3. Checkout the master branch $ git checkout master
    4. Reset to the commit you want your master to be pointed to $ git reset --hard <commit-number> in your case $ git reset --hard 055c700
    5. Force push master to heroku $ git push -f heroku master
    6. Delete the branch new_master

    You seem to be confusing the term HEAD to mean an actual branch. HEAD is just a pointer to the last commit of the current branch you are on. So creating a branch called HEAD would have no effect. If you are on the branch HEAD, the pointer HEAD would be at the last commit. If you are on master it will point to the last commit in master