垃圾收集git中的提交

Lop*_*Sae 11 git

我有一些提交由git subtree我想要垃圾收集(更多的任何实际目的只是为了了解什么和为什么可以收集).

我已经检查过这些提交没有通过以下方式引用:

# 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)
Run Code Online (Sandbox Code Playgroud)

这些是git gc文档列表可以包含引用的地方.

仍然存在给定的提交之后仍然存在git gc.

我错过了什么吗?或者是否有任何git plumbing命令检查所有这些引用?

Wil*_*uta 16

每次我想删除松散的对象时,我都使用以下命令:

rm -rf .git/refs/original/*
git reflog expire --all --expire-unreachable=0
git repack -A -d
git prune
Run Code Online (Sandbox Code Playgroud)


Lil*_*ard 6

提交(或一般的对象)实际上不会被删除,直到它们被解压缩到松散的物体中并且离开那里至少2周.您可以使用git gc --prune=now跳过2周的延迟.

通常情况下,git会将您的对象组合到一个packfile中.与松散物体相比,这提供了更好的压缩和效率.这通常在git gc执行时发生.但是,如果对象未被引用,git gc则将其解压缩回松散的对象.

一旦解压缩,git gc将自动修剪旧的松散未引用对象.这是由--prune=<date>标志控制的,默认为2周前,所以它修剪任何超过2周的旧的未引用对象.通过指定--prune=now,您要求git gc修剪任何比现在更旧的对象,这基本上意味着修剪任何存在的未引用对象.

  • @LopSae:您是否尝试过运行`git fsck --unreachable`以确保您的提交真的无法访问? (2认同)