Depending on whether you've already pushed your changes, you have two ways to delete the commit in Git.
IMPORTANT: Note that running these commands will DELETE your working directory changes. It is important to understand exactly which item(s) you are deleting before proceeding.
Any changes to tracked files in the working tree since <commit> are discarded. Be sure to separately save any changes you'd like to keep.
Deleting commits not yet pushed
If your changes are not yet pushed, simply run the following command:
git reset --hard HEAD~1
This command discards all working tree changes and moves HEAD to the commit before HEAD.
If you'd like to delete the commits up to a specific commit, run <git log>
into the command line to find the specific commit id, and then run the following command:
git reset --hard <sha1-commit-id>
This command discards all working tree changes and moves HEAD to the commit chosen.
Deleting commits already pushed
Alternatively, if your changes are already pushed, simply run the following command:
git push origin HEAD --force
Note that if others have pulled this branch, you are better off starting a new branch. If you don't do this when someone else pulls, it simply merges it into their work, and you will get it pushed back up again.
If you need to find a commit that you deleted, it is typically present in <git reflog>
unless you have garbage collected your repository.
Need help? Please contact us at support@assembla.com