temporarily undo commit(s) on a remote server

I do not claim to be a wiz at git, and I do not ensure what I am writing about, but it seemed to work for me, and I appreciate any comments.

My goal was to temporarily revert one or many commits that I had pushed to the remote server.

http://cheat.errtheblog.com/s/git — specifically the “Fix mistakes / Undo” section was helpful.

What I found:

git revert -n <sha>

#run this for each commit you would like to “undo”

(the -n makes it so that you are not actually creating a commit, but staging the reverse of the changes made by your <sha> commit in your index. git status will show you this)

git ci -a # apply your revision
git push #origin to master (these steps effectively created one commit that was the product of reversing all the commits you picked in the git revert -n step)

now your index looks like:

  • <sha1>… revision of <commit…s>
  • <sha2>… commit4
  • <sha3>… commit3
  • now, lets say, the time has come to reapply your commits. Because you didn’t just do

    git reset --hard &lt;commit3&gt;

    or something like that, all you have to do is git reset –hard <sha1> which will “undo your undo”


    git push #origin master

    again and you are back to where you were.

    • del.icio.us
    • Reddit
    • Technorati
    • Twitter
    • Facebook
    • Google Bookmarks
    • HackerNews
    • PDF
    • RSS
    This entry was posted in programming. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.