I had to delete a the last 5 commits from a local git repo, I did so by reset --hard to the new HEAD commit:
git reset --hard abcde1
Now I need to remove those unreferenced commits from the history, after reading many answers here I tried running the following.
git gc --prune=now
and
git prune --expire=now --agressive
None of the answers I found seem to work for me, for example I can still see a those commits with git show <sha>, what am I missing here? Is possible to remove a commit from history completely?
And finally, if I push to a new origin (let's say it's a completely new repo) are those unreferenced commits also pushed?
Unreferenced or orphaned commits will not be pushed to the origin. Those commits will be removed by git's garbage collection in sometime. Do this if you want to force the garbage collection
git config gc.reflogexpireUnreachable = now
git gc --prune=now
git config gc.reflogexpireUnreachable = "2 days"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With