找到你要的答案

Q:How to Prevent Garbage Collection in GIT?

Q:如何防止在git的垃圾吗?

Git mysteriously runs Garbage collection "from time to time" and deletes and orphaned commits you have.

https://www.kernel.org/pub/software/scm/git/docs/git-gc.html

Scientifically, this will occur approximately 6-8 hours before you realize you really needed that commit which was just deleted.

I'd rather not have my files deleted by Git. How can I disable automatic garbage collection altogether?

Git神秘地运行垃圾收集“不时”,删除和孤儿有你。

https://www.kernel.org/pub/software/scm/git/docs/git-gc.html

科学,这将出现约6-8小时在你意识到之前,你真的需要把刚刚被删除。

我不想把我的文件删除命令。我怎样才能完全禁用自动垃圾收集?

answer1: 回答1:

From the very same page you just linked to:

Some git commands may automatically run git gc; see the --auto flag below for details. If you know what you’re doing and all you want is to disable this behavior permanently without further considerations, just do:

$ git config --global gc.auto 0

从同一页你刚刚链接到:

一些Git命令会自动运行git GC;看到汽车旗下的细节。如果你知道你在做什么,你想要的是禁用这个行为永久没有进一步的考虑,只是做:

$ git config --global gc.auto 0
answer2: 回答2:

Another approach, recently documented in:Documentation/config: mention "now" and "never" for 'expire' settings

In addition to approxidate-style values ("2.months.ago", "yesterday"), consumers of 'gc.*expire*' configuration variables also accept and respect 'now' ("do it immediately") and 'never' ("suppress entirely").

See commit 8cc8816 (28 Jul 2015) by Eric Sunshine (sunshineco).
Suggested-by: Michael Haggerty (mhagger).
(Merged by Junio C Hamano -- gitster -- in commit 8cc8816, 28 Jul 2015)

That means this would also prevent any gc:

git config --global gc.pruneExpire never
git config --global gc.reflogExpire never

另一种方法,最近记录在:文档/配置:提“现在”和“永不”为'过期'设置

In addition to approxidate-style values ("2.months.ago", "yesterday"), consumers of 'gc.*expire*' configuration variables also accept and respect 'now' ("do it immediately") and 'never' ("suppress entirely").

See commit 8cc8816 (28 Jul 2015) by Eric Sunshine (sunshineco).
Suggested-by: Michael Haggerty (mhagger).
(Merged by Junio C Hamano -- gitster -- in commit 8cc8816, 28 Jul 2015)

这意味着这也将阻止任何GC:

git config --global gc.pruneExpire never
git config --global gc.reflogExpire never
git  garbage-collection