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


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

git reset --hard HEAD~1


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


For more reference:

By Keenlio, March 12, 2014

What do you think?

Leave a Reply

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

+ 6 = fifteen

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>