I have used git reset [SHA] and it works but when I try to make a push to origin master I get this message ! "[rejected] HEAD -> master (non-fast-forward)". I have no idea what to do at this point? If I make a pull it seems to bring back all the changes I tried to get rid of.
-
Have the commits you want to undo been pushed in the remote git repository (origin masteR)? Check this guide: https://github.com/blog/2019-how-to-undo-almost-anything-with-git – Mehdi Mar 01 '16 at 22:31
-
2Possible duplicate of [Revert Git repo to a previous commit](http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit) – cmbuckley Mar 01 '16 at 22:34
2 Answers
If you truly want to overwrite the master branch on the remote, you'll need to force push:
git push -f origin master
But warning! If others are using this repository you may cause them a lot of problems by doing this. If so, you should probably create a commit reverting the unwanted commits instead (see Revert Git repo to a previous commit).
It looks like the message you are getting is a non-fast-forward-error, meaning your push is being refused because another person has pushed to the same branch you pushed to. To be able to make your pushes, you need to first run a git fetch origin
, origin being the name you gave the remote. Then running a git status
to make sure you're in the clear. After, run a git merge origin YOUR_BRANCH_Name
, to merge the changes made online with those you made locally.

- 30,334
- 10
- 78
- 137

- 12
- 1