I have some commits created by git subtree
that I want to have garbage collect (more that any practical purpose just to understand what and why can get collected).
I have already checked that these commits are not referenced the following ways:
# In any reflog
> git reflog --all --no-abbrev-commit | grep <hash>
(no output)
# In any branch, local or remote
> git branch --contains <hash>
(no output)
> git branch -r --contains <hash>
(no output)
# In any tag
> git tag --contains <hash>
(no output)
# In the current index
> git rev-list HEAD | grep <hash>
(no output)
# In references from filter-branch
> ls .git/refs/original/
(the folder does not exist)
These are the place that git gc documentation lists that could contain references.
Still the given commits still exist after git gc
.
Am I missing something? Or is there any git plumbing command that checks all this references?
Every time I want to delete loose objects, I use the following commands:
rm -rf .git/refs/original/*
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
Commits (or objects in general) aren't actually deleted until they've been unpacked into loose objects and left that way for at least 2 weeks. You can use git gc --prune=now
to skip the 2 week delay.
Normally what happens is git will pack your objects together into a packfile. This provides much better compression and efficiency than having loose objects. This typically happens whenever a git gc
is executed. However, if an object is unreferenced, then git gc
will unpack it back into a loose object.
Once unpacked, git gc
will automatically prune old loose unreferenced objects. This is controlled by the --prune=<date>
flag, which defaults to 2 weeks ago, so it prunes any old unreferenced object older than 2 weeks. By specifying --prune=now
, you're asking git gc
to prune any objects that are older than right now, which basically means to prune any unreferenced objects that exist.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.