How to delete a 'git commit' from LOG, like it had never existed

This command (beware, it would rewrite history):

git rebase --onto commitHash^ commitHash

(@ouah's solution didn't work for me, and instead Lily's did, but his solution shouldn't be a comment, it should be an answer like this.)


If it is the last commit

git reset --hard HEAD^

if it is not the last commit

git rebase -i commit_hash^

an editor will open, delete the whole line with the commit, save and quit.

Note that rewriting history or rebasing if the branch has already been pushed is usually a bad idea and you may prefer to use

git revert commit_hash

that will add a new commit that reverts the commit commit_hash.

Tags:

Git