Git:Git 什么时候进行垃圾回收?

标签 git version-control garbage-collection git-gc

我想知道:Git 什么时候执行垃圾回收?我知道过去必须调用 git gc 来手动启动垃圾收集,但现在它是自动完成的,什么时候?

另外,在最新的Git版本中是否需要手动调用它?

最佳答案

大部分答案都在 git gc documentation 中:

--auto

With this option, git gc checks whether any housekeeping is required; if not, it exits without performing any work. Some git commands run git gc --auto after performing operations that could create many loose objects.

Housekeeping is required if there are too many loose objects or too many packs in the repository. If the number of loose objects exceeds the value of the gc.auto configuration variable, then all loose objects are combined into a single pack using git repack -d -l. Setting the value of gc.auto to 0 disables automatic packing of loose objects.

If the number of packs exceeds the value of gc.autopacklimit, then existing packs (except those marked with a .keep file) are consolidated into a single pack by using the -A option of git repack. Setting gc.autopacklimit to 0 disables automatic consolidation of packs.

这里唯一缺少的是对哪些“某些”命令可能运行 git gc --auto 以及何时运行的解释。此列表可能会更改,但查看当前的 git 源代码,这些突出:

git fetch
git merge
git receive-pack
git am
git rebase

(这是来自 git grep -e --auto -- '*.c' '*.sh' 和 eyeball-排除所有 t/ 测试脚本和其他明显的错误命中)。如果你想要更深入的东西,git 的源代码在 github.com...

备注:with Git 2.17 (Q2 2018) ,您还需要考虑:

git commit

关于Git:Git 什么时候进行垃圾回收?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28246216/

相关文章:

git - 子命令的 Bash 前缀命令名称

version-control - 如何组织我的所有代码、数据、脚本、任务等?

Git:检查文件是否存在于某个版本中

java - 如何检测一个对象只能弱可达?

git - 我似乎有太多远程分支。这怎么发生的?我如何解决它?

Git 在将更新 merge 到我的子树时感到困惑

github - 致命的 : cannot update the ref 'HEAD' : unable to append to '.git/logs/HEAD' : Bad file descriptor

svn - 使用 Tortoise SVN 进行单用户版本控制

java - 理解 Jvmstat 图

c# - WPF 中的低分配绘图