views:

920

answers:

3

Hey guys, 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.

Thanks.

+3  A: 

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
rnicholson
A: 

You wanted to use git revert HEAD to create a new commit that would undo the commit at HEAD. Instead you just moved HEAD back to the commit prior to the current HEAD.

Stuart
Thanks, that makes sense, though this probably would've been better as a comment given that it doesn't really fix my problem. Thanks though.
Jorge Israel Peña
+4  A: 

Now I just want to go back to the time before I issued the reset

If you only want to cancel the git reset --soft you just did, you can look up the former HEAD commit id in the reflogs

 $ git reflog
 $ git reset --soft formerCommit

And then you can prepare your git revert

VonC
Thanks, this is similar to what someone on IRC told me to do, but it's pretty confusing so I'm going to go with rnicholson's answer for documenting purposes.
Jorge Israel Peña
I wasn't familiar with git reflog. Very cool. Learned something new. This is probably a better solution as it condenses the first 3 steps of my answer to one command.
rnicholson