2

Possible Duplicate:
Git undo last commit

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

Community
  • 1
  • 1
Adam Lee
  • 24,710
  • 51
  • 156
  • 236

3 Answers3

3

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.

Yunchi
  • 5,529
  • 2
  • 17
  • 18
1

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
0

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.

Ashray Baruah
  • 1,585
  • 11
  • 7
  • 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 01:19