Reputation: 1237
I have some garbage commits in my git repositry. These have been created by e.g. the git gui when changing the latest commit again and accidently creating additional commits.
Now I have some commits lying around with no HEAD assigned (detached, not part of any branch).
As I want to tidy up, my question is: How can I delete these commits (see F, G and H)? Is this done using rebase or revert or reset? Or using another tool? On which commit do I have to sit to do it?
A -- B -- C -- D -- E [master]
\-- F -- G
\-- H
Thanks
Christian
Upvotes: 12
Views: 8489
Reputation: 1893
git reflog expire --expire=now --all
git gc --prune=now
Note: I know this is written in the comments of the most voted answer, but I keep finding myself coming back to this question and not immediately finding the answer that works.
The --all
option is the only thing that is missing from the most voted answer, but is what makes it work for me.
Upvotes: 4
Reputation: 301477
Do the below:
git config gc.reflogexpireUnreachable now
git gc --prune=now
git config --unset gc.reflogexpireUnreachable
Upvotes: 6