tags:

views:

1006

answers:

3

Hi,

How can I uncommit my last commit in git? I have googled it.

Is it

git reset --hard HEAD

or

git reset --head HEAD^

Thank you.

+4  A: 

git reset --hard HEAD^

note: if you're on windows you'll need to quote the HEAD^ so

git reset --hard "HEAD^"

tgeros
+5  A: 

It's the latter.

git reset --hard HEAD^, if you want to also throw away the changes you made. git reset --soft HEAD^ will keep the modified changes in your working tree.

nfm
`--hard`, not `--head` (I assume you just didn't notice that misprint)
David Zaslavsky
Haha thanks, copy-pasted it from the question :P
nfm
+12  A: 

Like the other answers say, it's:

git reset --hard HEAD^

Or leave off --hard if you want to keep the work tree, just back out the commit and index. --soft won't touch the index, either; you'll be in the state you were in immediately before committing.

But the other two answers neglect to mention why it's HEAD^ not HEAD, which was the original question. HEAD refers to the current commit - generally, the tip of the currently checked-out branch. The ^ is a notation which can be attached to any commit specifier, and means "the commit before". So, HEAD^ is the commit before the current one, just as master^ is the commit before the tip of the master branch.

Edit: In case the number and speed of upvotes indicates a trend toward frequent views, here's the portion of the git-rev-parse documentation describing all of the ways to specify commits (^ is just a basic one among many).

Jefromi