0

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"
aynber
  • 22,380
  • 8
  • 50
  • 63
Edito
  • 3,030
  • 13
  • 35
  • 67

1 Answers1

1

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

Edito
  • 3,030
  • 13
  • 35
  • 67
TheGeorgeous
  • 3,927
  • 2
  • 20
  • 33
  • step 5 don't you mean delete the branch `new_master`? – Edito May 05 '16 at 09:04
  • also step 3 should be `new_master` instead of `master`, am I right? – Edito May 05 '16 at 09:07
  • No, that is correct. It should be `master`. Your master branch would be reset to the commit `055c700` – TheGeorgeous May 05 '16 at 09:08
  • Ok issue is that the `master` branch contains an error that heroku doesn't let me deploy, every push from that branch is rejected. So I'm still stuck at step 3. --> https://i.imgur.com/Az9h96Y.png – Edito May 05 '16 at 09:13
  • Since your branch is ahead by two commits in heroku you will have to force push your branch using the `-f` option like this `git push -f heroku master` – TheGeorgeous May 05 '16 at 09:17
  • so `git push heroku master -f` instead of `git push heroku new_master -f` because that is what confuses me, I want the version of the branch `new_master` on heroku or am I thinking in the wrong direction here? – Edito May 05 '16 at 09:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111100/discussion-between-thegeorgeous-and-edward). – TheGeorgeous May 05 '16 at 09:19
  • "HEAD is just a pointer to the last commit of the current branch you are on." -- This is incorrect. HEAD is usually a reference to the most recent commit on the current branch. There are times when HEAD can point at older commits on a branch. – masukomi May 05 '16 at 11:47
  • 1
    @masukomi was just trying to give a simple explanation – TheGeorgeous May 05 '16 at 11:50
  • yes, @TheGeorgeous but it can be said simply without leaving newbs with a belief system that will leave them confused when they hit the edge cases. Best to be simple _and_ accurate whenever possible. Especially in programming. – masukomi May 05 '16 at 11:53