Delete a git commit
Posted: 2023-07-17 Filed under: system | Tags: commit, delete, git, github, remove, revert 2 CommentsI’ve been preparing a few (very preliminary) ports that I do not wish to push to my git repo with the rest. However, being tired and all, I did a git commit -a, so they ended up there. So far, whatever experience I’ve got with git, it was always by going forward… I did revert the commit, but wanted to know how to delete it completely.
I did a few searches and found relevant instructions. In my case, I wanted to remove the last 5 commits (consecutive) and just start over. My git history was clean of changes, therefore:
git reset --hard HEAD~5
Since I had already pushed them, I needed to remove from remote:
git push origin HEAD --force
Obligatory: be careful when doing this!

I use
git rebase -i HEAD~20
here -i means interactive, 20 is how many last commits to show.
There are hints inside what to do. This allows delete commits, glue together several commits, rephrase the comment, and so on.
thanks, Anonymous reader, that’d be very helpful.