How To Delete a Commit from a Git Repository

In this blog post, I will show you how to delete a git commit from a Git repository.

Revert

 We delete commits using the revert operation and remove the commit from the repository.

Once a commit has been reverted, the repository will roll back to the state it was before the commit of the reverted git.

View Log

Before we revert a commit, let’s change all the commit operations using the following command.

git log --oneline

Revert

To revert the repository, copy the commit ID that you would like to remove and run the following command.

git revert 01b4e8b

If you recheck the repository, you will see that all the files that were added from the commit that was reverted have been deleted.

Processing…
Success! You're on the list.