I did a git commit
but I have not pushed it to the repository yet.
So when I do git status
, I get \'# Your branch is ahead of \'master\' by 1 commi
IF you have NOT pushed your changes to remote
git reset HEAD~1
Check if the working copy is clean by git status
.
ELSE you have pushed your changes to remote
git revert HEAD
This command will revert/remove the last one commit/change and then you can push
Remove the last commit before push
git reset --soft HEAD~1
1
means the last commit, if you want to remove two last use 2
, and so forth*
git reset --hard origin/master
to reset it to whatever the origin was at.
This was posted by @bdonlan in the comments. I added this answer for people who don't read comments.
Simply type in the console :
$ git reset HEAD~
This command discards all local commits ahead of the remote HEAD
This is what I do:
First checkout your branch (for my case master
branch):
git checkout master
Then reset to remote HEAD^ (it'll remove all your local changes), force clean and pull:
git reset HEAD^ --hard && git clean -df && git pull