GIT delete or undo last commit

Delete or undo mean it is as if you did not want that commit and when you do a git push in the future, the changes will not push to the remote branch.
If you created the changes and commit to local master repo, and you still want the changes, create a new branch before delete/undo/reset the commit. This way, your new changes will be in the new created branch.
Now go to delete the commit in master repo.

git reset --hard

WILL DELETE YOUR WORKING DIRECTORY CHANGES

If you are sitting on that commit, this command will delete it

git reset --hard HEAD~1

or

git reset --hard HEAD^

To find out the id of the commit you want to delete

git log

and run this command

git reset --hard <id of the commit>

If you pushed, you should use

git revert

instead.

For more reference:

http://git-scm.com/docs/git-reset

http://stackoverflow.com/questions/1338728/how-can-i-delete-a-git-commit

By Keenlio, March 12, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


five × 2 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>