在Git中测量/计数对象以查看我是否接近自动包装 [英] Measure / count objects in Git to see whether I am close to auto-packing
问题描述
我想对git中的对象进行测量/计数以查看是否接近自动打包,我认为可以通过对.git/objects/...中的文件进行计数来完成此操作,但是我不确定.
I would like to measure / count objects in git to see whether I am close to auto-packing, I think it can be done trivially by counting files in .git/objects/..., but I am not sure.
这是故事:
几天以来,每当我推送到git repo时,它都会自动打包. (git仓库位于USB记忆棒上,因此自动打包速度非常慢,大约30分钟后我就取消了它)
For a couple of days now, my git repo is auto-packing itself whenever I push to it. (The git repo lives on a USB memory stick, therefore the auto-packing is awfully slow and I have cancel it after 30 minutes or so)
与以下问题相同:
我的git仓库有问题.在过去的两天内,每当我推送到服务器时,我都会收到以下消息:自动打包存储库以获得最佳性能"
I'm having a problem with my git repo. For the last couple of days whenever I do a push to the server I get this message: "Auto packing the repository for optimum performance"
在同一线程中,我找到了解决方案:
In that same thread I found the solution:
要为一个项目禁用:
To disable for one project:
cd your_project_dir
cd your_project_dir
git config gc.auto 0
git config gc.auto 0
要全局禁用:
git config --global gc.auto 0
git config --global gc.auto 0
这解决了我针对该特定存储库的问题...
That solved my problem for that particular repo...
...但是我的记忆棒上还有更多的git repo,我想知道一种方法来衡量我的其他git repos是否接近自动打包
...but I have got many more git repo's on my memory stick and I would like to know a way to measure if any of my other git repos is close to auto-packing
我发现:
Git根据两个条件决定是否自动执行gc:
Git decides whether to auto gc based on two criteria:
包装太多吗? (从字面上看,.git/objects/pack中是否有超过50个带有.idx的文件?)
Are there too many packs? (Literally, are there more than 50 files with .idx in .git/objects/pack?)
是否有太多的松散物品? (从字面上看,.git/objects/17中是否有27个以上的文件?)
Are there too many loose objects? (Literally, are there more than 27 files in .git/objects/17?)
我的问题几乎可以回答,但我只是想确认自己已正确理解:如何测量/计算松散的物体以查看是否接近自动包装? -是否确实按照上述答案中的建议(如上述答案所示)对.git/objects/17中的文件进行计数并与硬限制27相比较,
My question is almost answered, but I would simply like to have confirmation that I understand correctly: How can I measure / count loose objects to see if I am close to auto-packing ? -- is it (as suggested in the above answer) literally counting files in .git/objects/17 and compare to the hard limit of 27,
-还是正在计数.git/objects/01,.../02,.../03等中的所有文件,并将平均值与git config global中定义的软限制进行比较?
-- or maybe it is counting all files in .git/objects/01, .../02, .../03, etc... and comparing the average to a soft limit defined in git config global ?
-即使琐碎,还是有一个git命令来计算.git/objects/17中的对象? -是否有git命令返回硬限制27?
-- even if it is trivial, is there a git command that counts objects in .git/objects/17 ? -- is there a git command that returns the hard limit of 27 ?
推荐答案
The answer at Why does git run auto-packing on every push to our repo? is still valid. As you can see in the source code of the latest release of git (2.10.2), this is the function need_to_gc
that decides whether gc is run.
- 选项
gc.auto
是否设置为0或负数? - 是否存在
too_many_packs
:选项gc.autopacklimit
(默认值为50)是否为正数且小于包数(.git/objects/pack
中的*.idx
个文件)? - 是否存在
too_many_loose_objects
:选项gc.auto
(默认值为6700)为正数,并且是.git/objects/17
中的松散对象的数量(仅在此目录中查找;不计算全部,并且取平均值或最大值或类似的值) )大于({gc.auto} + 255)/256)
?
- Is the option
gc.auto
is set to 0 or negative? - Are there
too_many_packs
: is the optiongc.autopacklimit
(default 50) positive and less than the number of packs (*.idx
files in.git/objects/pack
)? - Are there
too_many_loose_objects
: is the optiongc.auto
(default 6700) positive, and is the number of loose objects in.git/objects/17
(it looks only in this directory; doesn't count all and take average or max or anything like that) greater than({gc.auto} + 255)/256)
?
所以这就是数字27的来源:它是(6700 + 255)/256的下限.您可以通过增加gc.auto
来增加它.您可以使用git命令git config --get gc.auto
获得与该数字27相等的值,但这仅在显式设置了该选项的情况下有效.
So that's where the number 27 comes from: it's the floor of (6700 + 255)/256. You can increase it by increasing gc.auto
. You can get the equivalent of this number 27 with the git command git config --get gc.auto
but that only works if the option has been explicitly set.
这篇关于在Git中测量/计数对象以查看我是否接近自动包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!