Can't Push After git reset --soft HEAD^

Jorge Israel Peña picture Jorge Israel Peña · Jan 6, 2010 · Viewed 8.6k times · Source

Just now I committed and pushed something (yes, my mistake on the push) that I decided I should 'revert' or 'undo'. So I was told to issue git reset --soft HEAD^ on my end, and I figured this would somehow create a 'revert' commit that once committed would make it as if the change never happened. I don't mind if the history of the change is there at all, that's just what I imagined would happened.

Anyways, after having done that I committed again, and then when I tried to push I got the non-fast-forward error. Now, I know I screwed something up with the reset, something along the lines of my tree and origin tree are 'mismatched' now, but I am wondering how to fix this. Now I just want to go back to the time before I issued the reset, so that I can just manually revert the changes by taking them out manually and then committing, unless someone else can recommend the correct way of reverting a pushed commit, and by this I don't mean that the history has to be gone from the log or anything.

Answer

rnicholson picture rnicholson · Jan 6, 2010

If I understand your problem correctly you could try the following:

(I'm assuming this is your 'master' branch and you are pushing to 'origin')

Sync up with your remote to get to the same state.

git remote update
git checkout master
git merge origin/master

Now revert your commit

git revert HEAD (or where ever the commit you want to revert is now)
git commit -av

Sync up with your remote

git push