We came, we saw, we concurred
Loosely Typed in Ohio

Undoing Commits in Git

Some days, more than others, I love having moved to Git.

Kent had pulled some changes from our central git repository to a staging environment. These changes weren’t tested very well in IE6, so he wanted to remove them entirely from the staging environment. In Subversion, we’d have done something like svn update -r120 if we were on revision 121.

After a little digging – Kent says I only roll 3d20 for Source Control now, because we’re geeks – I found that Kent could go into the staging environment and do git reset --hard HEAD^; that is, revert everything in this repository to the state it was in one commit before the current HEAD. Then, after making a second commit from dev and pushing it, we can do a normal git pull and it will fast-forward us to the new commit.

So this isn’t much different from Subversion so far. What you can do that SVN explicitly is designed to not let you do, is use that in your dev environment. If you haven’t yet pushed the changes to a remote repository, you can willy-nilly undo commits you’ve made.

Did you accidentally add and commit a file that shouldn’t be in the repository at all? git reset --hard HEAD^, just like before. Did you commit a little prematurely? git reset HEAD^, which does a soft reset, which leaves all the changes intact but removes them from the repository like they were never committed.

Put that in SVN’s pipe and smoke it.

Leave your mark

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Close
E-mail It
Socialized through Gregarious 42