Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I un-do a git commit AFTER a git push?

Tags:

git

From here http://blog.prabir.me/post/Undo-in-Git.aspx, it said

This undo’s your commit and also resets your working tree to the last commit.

1 git reset --hard HEAD^

But how can I un-do my last commit AFTER I did a 'git push'?

Thank you.

When I do 'git log', I get as my top commit

commit 29fc764693a5933a379169e22891e4b0d3d2426f
Merge: 002db49 cfb1d8f

How can I 'git revert' that change?

I get this

$ git revert HEAD 
fatal: Commit 29fc764693a5933a379169e22891e4b0d3d2426f is a merge but no -m option was given.
like image 396
michael Avatar asked Jan 03 '12 17:01

michael


1 Answers

you can use git revert HEAD, which generates a new commit, which will undo the changes in your previous commit. Look here. Note however that both the commit and the revert commit will show up in the history.

Edit: As KingChrunch mentioned, when reverting a merge commit, you need to specify which parent you want to revert to, so add -m <parent>. Of course simply following the link I have posted would have told you so.

You can't (well actually shouldn't) modify the history of a shared repository. If you where inclined to modify the history (please don't), you can use git reset with git push --force, or git rebase.

like image 69
Grizzly Avatar answered Sep 20 '22 14:09

Grizzly