git gc和git repack -ad之间有什么区别吗? git prune`? [英] Is there any difference between `git gc` and `git repack -ad; git prune`?

查看:107
本文介绍了git gc和git repack -ad之间有什么区别吗? git prune`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git gcgit repack -ad; git prune之间是否有区别?
如果是,git gc将执行哪些其他步骤(反之亦然)?
在空间优化或安全性方面,哪个更好使用?

Is there any difference between git gc and git repack -ad; git prune?
If yes, what additional steps will be done by git gc (or vice versa)?
Which one is better to use in regard to space optimization or safety?

推荐答案

git gcgit repack -ad; git prune之间是否有区别?

Is there any difference between git gc and git repack -ad; git prune?

区别在于,默认情况下git gc对于需要执行哪些内务处理任务非常保守.例如,除非存储库中的松散对象数量超过某个阈值(可通过gc.auto变量配置),否则它将不会运行git repack.此外,git gc将要运行的任务比git repackgit prune还要多.

The difference is that by default git gc is very conservative about what housekeeping tasks are needed. For example, it won't run git repack unless the number of loose objects in the repository is above a certain threshold (configurable via the gc.auto variable). Also, git gc is going to run more tasks than just git repack and git prune.

如果是,git gc将执行哪些其他步骤(反之亦然)?

If yes, what additional steps will be done by git gc (or vice versa)?

根据文档git gc运行:

  • git-prune
  • git-reflog
  • git-repack
  • git-rerere
  • git-prune
  • git-reflog
  • git-repack
  • git-rerere

更具体地说,通过查看源代码gc.c(第338-343行) 1 我们可以看到它最多调用 以下命令:

More specifically, by looking at the source code of gc.c (lines 338-343)1 we can see that it invokes at the most the following commands:

  • pack-refs --all --prune
  • reflog expire --all
  • repack -d -l
  • prune --expire
  • worktree prune --expire
  • rerere gc
  • pack-refs --all --prune
  • reflog expire --all
  • repack -d -l
  • prune --expire
  • worktree prune --expire
  • rerere gc

取决于包装的数量(第121- 126),它可能会运行带有-A选项的repack而不是(第203-212行):

Depending on the number of packs (lines 121-126), it may run repack with -A option instead (lines 203-212):

* If there are too many loose objects, but not too many
* packs, we run "repack -d -l". If there are too many packs,
* we run "repack -A -d -l".  Otherwise we tell the caller
* there is no need.
if (too_many_packs())
    add_repack_all_option();
else if (!too_many_loose_objects())
    return 0;

关于第211-212行的通知>函数,如果存储库中没有足够的松散对象,则gc根本不会运行.

Notice on line 211-212 of the need_for_gc function that if there aren't enough loose objects in the repository, gc is not run at all.

这在文档中进一步阐明:

如果有太多的松散物品或太多物品,则必须进行客房整理 存储库中有很多包.如果松散物体的数量超过 gc.auto配置变量的值,然后全部松动 使用git repack -d -l将对象组合成一个包. 将gc.auto的值设置为0会禁用自动打包 松散的物体.

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.

如果包装数量超过gc.autoPackLimit的值,则 现有的软件包(标有.keep文件的软件包除外)是 通过使用git repack-A选项合并为单个包.

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.

如您所见,git gc致力于根据存储库的状态来做正确的事情.

As you can see, git gc strives to do the right thing based on the state of the repository.

在空间优化或安全性方面,哪个更好用?

Which one is better to use in regard to space optimization or safety?

通常,最好运行git gc --auto仅仅是因为它将做最少的工作即可使存储库保持良好状态-安全且不会浪费太多资源.

In general it's better to run git gc --auto simply because it will do the least amount of work necessary to keep the repository in good shape – safely and without wasting too many resources.

但是,请记住,除非通过将gc.auto配置变量设置为0来禁用此行为,否则某些命令可能已经自动触发了垃圾回收.

However, keep in mind that a garbage collection may already be triggered automatically following certain commands, unless this behavior is disabled by the setting the gc.auto configuration variable to 0.

文档:

-自动
使用此选项,git gc检查是否需要任何内务处理;如果没有,它将退出而不执行任何工作.一些git 命令执行了可能会导致错误的操作后运行git gc --auto 创建许多松散的对象.

--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.

因此,对于大多数存储库,您都不需要经常频繁地显式运行git gc,因为它将已经为您解决了.

So for most repositories you shouldn't need to explicitly run git gc all that often, since it will already be taken care of for you.

1.截至2016年8月8日提交 a0a1831 以来.

1. As of commit a0a1831 made on 2016-08-08.

这篇关于git gc和git repack -ad之间有什么区别吗? git prune`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆