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

This question already has an answer here:

I have run git status and

# On branch master
# Your branch is ahead of 'origin/master' by 4 commits.
#   (use "git push" to publish your local commits)
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   app/views/layouts/_header.html.erb
#
no changes added to commit (use "git add" and/or "git commit -a")

I want undo all the 4 commits and changes not staged for commit before commiting to my remote repository. How can i do this?

share|improve this question

marked as duplicate by The Shadow, krlmlr, CraigTeegarden, jszumski, eddi May 30 '13 at 13:30

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.

up vote 14 down vote accepted

This will throw away all local changes in the working tree and the four latest commits:

git reset --hard HEAD~4
share|improve this answer

You can also run the following to reset to the remote's HEAD:

git reset --hard <REMOTE>/<BRANCH_NAME>

Ex:

git reset --hard origin/master
share|improve this answer

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