New repo, no remote (so: no pushing), no tags used.
» echo "aaa" > aaa
» git init
» git add .
» git commit -a -m "Added aaa"
» echo "bbb" > aaa
» git commit -a -m "This commit is wrong"
f9892d8 : author : 1 second ago : (HEAD, master) : This commit is wrong
e80f2bd : author : 14 seconds ago : : Added aaa
» git reset --hard HEAD~1
e80f2bd : author : 14 seconds ago : : Added aaa
» git checkout f9892d8
Note: checking out 'f9892d8'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at f9892d8... This commit is wrong
So, even after git reset --hard
the commit is still there. Doing garbage collection (git gc
) does also not help.
I really want to get rid of the wrong commit, forever. As if it never existed. Not in this branch, not in any branch, not in the history, nowhere!
Is it possible to tell git "forget this commit, it never existed"?
EDIT
To make it perfectly clear: I am not interested in removing the commit from the current branch, but on removing the commit from the whole repo. No traces of it must be anywhere in the repo: not in another branch, not as orphan commits, simply nowhere. As if it never existed.