How to delete/remove a commit from Git
Contents
Did you submit your password or some authentication to Github and want to delete them?
Then, take a few minutes to have a look this post to find out how to use git rebase figure it out.
- You need to use
git logto find the commit id that you want to delete it. - To use
git rebase -i [commit id]interactive model, you open up a file which you can edit. - Find out the commit that you want to delete and use vim(if you have otherwise you need use what kind of editor you are using) to replace the text
picktodrop. - Then,
git push origin HEAD:main --force. Notice, main is the branch which include the commit that you want to delete. - Refresh commit history page to ensure if it is deleted.
Problems
- You needs to change the setting on Github If you are using Github. To
cancel pull requestandallow force requestfrom settings in your repository. - If you are encoutering some steps that I am not showing here, please follow the command line tips, carefully.