-1

I am trying to restore an earlier state of my repository. I want to remove all commits made since a certain point. There are twelve commits I want to remove. I tried running git reset --hard HEAD~12 followed by git push, and I got the following error:

! [rejected] gh-pages -> gh-pages (non-fast-forward) error: failed to push some refs to 'the_repo' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I read up about non-fast-forward and I think that I actually do want to do that (i.e. there is nothing in those twelve commits I want to save). How can I successfully undo those commits?

hexidian
  • 81
  • 1
  • 10
  • Use `git push --force`. This will overwrite the remote history with your local history, discarding any commits on the corresponding branch of the remote that don't exist locally. – larsks Jan 11 '20 at 00:16
  • Right, "non-fast-forward" is a jargon-y way of saying "this is going to lose some commits, perhaps forever". But you *want* that other Git repository to lose those commits, perhaps forever. So use `--force-with-lease` or `--force`. – torek Jan 11 '20 at 00:16
  • Does this answer your question? [Cannot push to GitHub - keeps saying need merge](https://stackoverflow.com/questions/10298291/cannot-push-to-github-keeps-saying-need-merge) – phd Jan 11 '20 at 08:19
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Jan 11 '20 at 08:19

1 Answers1

0

I simply had to do git push --force

hexidian
  • 81
  • 1
  • 10
  • Help me understand how a `git push` resets the repo? That sounds like it forces the push to the remote, overwriting what's currently there in the remote. – benhorgen Jan 11 '20 at 02:23
  • 1
    `git push --force` fixes it after already doing the `git reset --hard HEAD~12` from the original question – hexidian Jan 11 '20 at 04:02
  • That makes me think the `git reset --hard ...` command was the real fix. I didn't think a `git push --force` alone would do the trick. Thanks for the feedback. – benhorgen Jan 11 '20 at 18:55