Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

Possible Duplicate:
Git undo last commit

After using git commit , how can I discard this commit and revert to my original state?

share|improve this question

marked as duplicate by nhahtdh, Greg Hewgill, bitmask, Simon, Michael Berkowski Jun 22 '12 at 2:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

git reset HEAD^ will undo the last commit, and the changes you made in that commit will be unstaged but still remain.

git reset HEAD^ --hard will undo the commit and delete the changes made in the last commit.

Likewise, git reset HEAD^^ will go back 2 commits.

The Git Community Book is a great reference for learning to use git.

share|improve this answer

You can "undo" a commit like this using:

git reset HEAD^

The files that you changed in the commit will remain modified in your working directory (see git status). If you use git reset --hard HEAD^, then the changes you made in the most recent commit will additionally be discarded.

share|improve this answer

If you want to discard all changes with no way of going forward, use:

git reset --hard HEAD

Over here, HEAD is the ID of any of your previous commits. To roll back just one commit, get the commit id using:

git log

And then use:

git reset --hard 13cca2414skfrrrereaaa

13cca2414skfrrrereaaa - is what the commit id might look like.

share|improve this answer
    
The commit hash of the commit before HEAD is aliased as HEAD^, which saves you from having to look that up with git log. By the way, the hash has an alphabet of 0-1a-f, so your "id" would be invalid as it uses the characters s,k,f and r. – bitmask Jun 22 '12 at 1:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.