如何在 Git 远程存储库上触发垃圾收集?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3162786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:40:03  来源:igfitidea点击:

How can I trigger garbage collection on a Git remote repository?

gitrepositorygit-gc

提问by peterwang

As we know, we can periodically run git gcto pack objects under .git/objects.

众所周知,我们可以定期运行git gc以打包.git/objects.

In the case of a remote central Git repository (bare or not), though, after many pushes, there many files under myproj.git/objects; each commit seems to create a new file there.

但是,在远程中央 Git 存储库(裸机或非裸机)的情况下,经过多次推送,在myproj.git/objects;下有很多文件;每次提交似乎都会在那里创建一个新文件。

How can I pack that many files? (I mean the ones on the remote central bare repository, not on local clone repository.)

我怎样才能打包这么多文件?(我的意思是远程中央裸存储库上的那些,而不是本地克隆存储库上的那些。)

采纳答案by Neil Mayhew

The remote repo should be configured to run gc as needed after a commit is made. See the documentation of gc.auto in git-gc and git-config man pages.

远程存储库应配置为在提交后根据需要运行 gc。请参阅 git-gc 和 git-config 手册页中的 gc.auto 文档。

However, a remote repo shouldn't need all that much garbage collection, since it will rarely have dangling (unreachable) commits. These usually result from things like branch deletion and rebasing, which typically happen only in local repos.

但是,远程存储库不应该需要那么多垃圾收集,因为它很少有悬空(无法访问)提交。这些通常是由分支删除和重新定位等原因引起的,这通常只发生在本地存储库中。

So gc is needed more for repacking, which is for saving storage space rather than removing actual garbage. The gc.auto variable is sufficient for taking care of this.

所以重装更需要gc,这是为了节省存储空间而不是去除实际的垃圾。gc.auto 变量足以解决这个问题。

回答by Neil Mayhew

While you should have some process that takes care of this periodically, automatically, it's no problem run

虽然您应该有一些进程可以定期自动处理此问题,但运行没有问题

git gc

on a bare repository

在一个裸仓库上

git@domU:/pix/git/repositories/abd.git$ ls -l

total 28
drwxrwxr-x   2 git git    6 2010-06-06 02:44 branches
-rw-rw-r--   1 git git   66 2010-06-06 02:44 config
-rw-r--r--   1 git git   23 2011-03-15 18:19 description
-rw-rw-r--   1 git git   23 2010-06-06 02:44 HEAD
drwxrwxr-x   2 git git 4096 2010-06-06 02:44 hooks
drwxrwxr-x   2 git git   20 2010-06-06 02:44 info
drwxrwxr-x 260 git git 8192 2010-09-01 00:26 objects
drwxrwxr-x   4 git git   29 2010-06-06 02:44 refs

$ git gc
Counting objects: 3833, done.
Compressing objects:  31% (1085/3500)...

回答by Igor Zevaka

This questionshould shed some light on how often you should run garbage collection.

这个问题应该说明你应该多久运行一次垃圾收集。

The easiest option would be to use a scheduled task in windows or a cron job in Unix to run git gcperiodically. This way you don't even need to think about it.

最简单的选择是使用 Windows 中的计划任务或 Unix 中的 cron 作业git gc定期运行。这样你甚至不需要考虑它。

回答by VonC

after many pushes, there many files under myproj.git/objects

多次推送后,下有很多文件 myproj.git/objects

There won't be as much with git 2.11+ (Q4 2016) and a pre-receive hook.
In that scenario, you won't have to trigger a git gcat all.

git 2.11+(2016 年第 4 季度)和 pre-receive hook 不会有那么多。
在这种情况下,你不会有触发git gc所有

See commit 62fe0eb, commit e34c2e0, commit 722ff7f, commit 2564d99, commit 526f108(03 Oct 2016) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster--in commit 25ab004, 17 Oct 2016)

请参阅Jeff King ( ) 的commit 62fe0ebcommit e34c2e0commit 722ff7fcommit 2564d99commit 526f108(2016 年 10 月 3 日(由Junio C Hamano合并-- --commit 25ab004,2016 年 10 月 17 日)peff
gitster

receive-pack: quarantine objects until pre-receive accepts

In order for the receiving end of "git push" to inspect the received history and decide to reject the push, the objects sent from the sending end need to be made available to the hook and the mechanism for the connectivity check, and this was done traditionally by storing the objects in the receiving repository and letting "git gc" to expire it.

Instead, store the newly received objects in a temporary area, and make them available by reusing the alternate object store mechanism to them only while we decide if we accept the check, and once we decide, either migrate them to the repository or purge them immediately.

receive-pack: 隔离对象直到预接收接受

为了让“git push”的接收端检查接收到的历史记录并决定拒绝推送,从发送端发送的对象需要对钩子和连通性检查机制可用,这就完成了传统上通过将对象存储在接收存储库中并让“ git gc”使其过期。

相反,将新接收的对象存储在临时区域中,并仅在我们决定是否接受检查时通过对它们重用备用对象存储机制使它们可用,一旦我们决定,要么将它们迁移到存储库,要么立即清除它们.

That temporary area will be set by the new environment variable GIT_QUARANTINE_ENVIRONMENT.

该临时区域将由新的环境变量设置GIT_QUARANTINE_ENVIRONMENT

That way, if a (big) push is rejected by a pre-receivehook, those big objects won't be laying around for 90 days waiting for git gcto clean them up.

那样的话,如果一个(大)推被一个pre-receive钩子拒绝了,那些大物体将不会在 90 天内等待git gc清理它们。