1

I have a single branch (master) on my git repo. I have been pushing commits to my remote repo.

I now want to revert back to a previous commit, and start from there again.

I have run the following:

git reset --hard <commit hash>

Now the head is at my chosen commit, from here I want to push this chosen commit as the head to my remote master branch.

git push origin master 

It won't work - error message stats

'Updates were rejected because a pushed branch tip is behind its remote counterpart.'

How do I checkout a previous commit locally, set the head to be at that commit and then push to my remote repo?

Thank you

Jonny
  • 1,053
  • 1
  • 13
  • 26
  • 1
    Possible duplicate of [Git push after reset](https://stackoverflow.com/questions/49114300/git-push-after-reset) – phd Apr 27 '19 at 19:20
  • https://stackoverflow.com/search?q=%5Bgit%5D+push+after+reset – phd Apr 27 '19 at 19:20

1 Answers1

3

The $ git reset --hard commit part is okay, you just need to do $ git push --force origin master

blinkofaneye
  • 148
  • 10
  • Thank you blinkofaneye, that worked pretty much. Only slight bug is that it gives me this message when i try to update then pull again: You are not currently on a branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull – Jonny Apr 27 '19 at 19:22
  • maybe you need to do ```git checkout master``` before doing ```git pull``` – blinkofaneye Apr 27 '19 at 19:27
  • This all worked perfectly, thank you. I suppose it would be an even better situation to revert back to an old commit and use that commit going forward but to keep the other commits that i have subsequently overwritten and deleted using this method. This way works fine for me though. Thank you – Jonny 9 secs ago Edit Delete – Jonny Apr 27 '19 at 19:33