Reputation: 1370
I accidentally added a tmp directory with some large files to my (only) local git repository (the .git directory now has a too big size of 134 MB).
I looked how to "remove" this last commit and found the command git reset --hard HEAD~1
and did it. If I run git log
and look in gitk the last commit is indeed gone. But if I check the size of the .git directory again it still has the size of 134 MB. If I search for large files in .git/objects/ I find a file with the exact size of the video file. So it seems that the files of the deleted commit are still there. I want to remove this file in the .git directory. I already tried git clean -n
but nothing is displayed to be deleted.
So my question is how to remove/clean/purge the .git directory from "unused" files.
Upvotes: 0
Views: 75
Reputation: 490068
If you really want it gone immediately—it will go away on its own eventually, which is a lot easier—you must rid yourself of the reflog entries that eftshift0 mentions in a comment. There are likely exactly two: one for the previous value of HEAD
, and one for the previous value of the branch that HEAD
itself names. In some cases, there may be more; rarely, there might be fewer.
To do this, use git reflog expire --expire-unreachable=now --all
. Note that this will remove all unreachable reflog entries from all references plus HEAD
. The definition of unreachable here is the same as the one in Think Like (a) Git: in this particular case "reachable" means "reachable from the current value of the reference itself". This particular change cannot be undone, so you should be very sure you don't want any discarded commits back before doing this.
Once you have done that, run git gc --prune=now
to remove the unreferenced commit and its unreferenced file.
Upvotes: 1