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.

  1. You need to use git log to find the commit id that you want to delete it.
  2. To use git rebase -i [commit id] interactive model, you open up a file which you can edit.
  3. 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 pick to drop.
  4. Then, git push origin HEAD:main --force. Notice, main is the branch which include the commit that you want to delete.
  5. Refresh commit history page to ensure if it is deleted.
  • You needs to change the setting on Github If you are using Github. To cancel pull request and allow force request from settings in your repository.
  • If you are encoutering some steps that I am not showing here, please follow the command line tips, carefully.

Related Content