如何简单地查找Git存储库的大小?
我不是指在我的存储库根目录上执行du -h
。由于我有很多被忽略的文件,因此该大小将与我的总存储库大小不同。我想知道克隆我的存储库需要传输多少数据。
请注意,自从 git 1.8.3(2013年4月22日)起:
"
git count-objects
"学会了"--human-readable
",也称为"-H
"选项,以适当的比例缩放显示各种大数字,如Ki
/Mi
/GiB
。
这可以与Jack Morrison在他的回答中提到的-v
选项结合使用。
git gc
git count-objects -vH
此外(仍为git 1.8.3),输出更加完整:
"
git count-objects -v
"已经学会报告对象存储中剩余的临时打包文件和其他垃圾。
更新:git 1.8.3 引入了一种更有效的获取粗略大小的方法:
git count-objects -vH
(请参见 @VonC 的答案)。
对于“完整大小”的不同想法,您可以使用以下方法:
git bundle create tmp.bundle --all
du -sh tmp.bundle
接近但不完全正确:
git gc
du -sh .git/
使用后者,你也会计算:
du
来测量该文件的大小。 - sehegit命令
git count-objects -v
使用-v选项可以较好地估计git仓库的大小。不加-v选项,它只会告诉你未打包文件的大小。这个命令可能不在你的$PATH中,你可能需要找到它(例如,在Ubuntu上我发现它在/usr/lib/git-core/中)。
来自Git man页面:
-v, --verbose
除了 loose 对象数量和磁盘空间消耗之外,它还会报告 pack 中对象的数量、pack 的数量、这些 pack 消耗的磁盘空间以及可以通过运行 git prune-packed 命令删除的对象数量。
输出结果类似于以下内容:
count: 1910
size: 19764
in-pack: 41814
packs: 3
size-pack: 1066963
prune-packable: 1
garbage: 0
你要找的是 size-pack
。那就是所有压缩提交对象的大小,或者说是新克隆存储库的最小可能大小。
git-count-objects -v
无法使用(因为它不在我的PATH中)时,git count-objects -v
是有效的。 - mwolfetechgit count-objects -v
之前运行 git gc
,因为你的仓库可能还没有被打包。可以参考这里第一个答案的论据:https://dev59.com/k3A65IYBdhLWcg3w-z1A - Jack Morrisongit count-objects -vH | grep 'size-pack'
。在这个命令中,H
参数是用来以人类可读的格式显示信息,就像@VonC在他的答案中提到的那样。 - alko989git count-objects --help
:size-pack:包占用的磁盘空间,以KiB为单位(除非指定了-H)。 - auralbee如需更多详细信息,您可以使用git-sizer
。在--verbose
设置中,示例输出如下所示。 Total size of files
行仅计算最大提交中文件的大小。您需要对大小值求和。
$ git-sizer --verbose
Processing blobs: 1652370
Processing trees: 3396199
Processing commits: 722647
Matching commits to trees: 722647
Processing annotated tags: 534
Processing references: 539
| Name | Value | Level of concern |
| ---------------------------- | --------- | ------------------------------ |
| Overall repository size | | |
| * Commits | | |
| * Count | 723 k | * |
| * Total size | 525 MiB | ** |
| * Trees | | |
| * Count | 3.40 M | ** |
| * Total size | 9.00 GiB | **** |
| * Total tree entries | 264 M | ***** |
| * Blobs | | |
| * Count | 1.65 M | * |
| * Total size | 55.8 GiB | ***** |
| * Annotated tags | | |
| * Count | 534 | |
| * References | | |
| * Count | 539 | |
| | | |
| Biggest objects | | |
| * Commits | | |
| * Maximum size [1] | 72.7 KiB | * |
| * Maximum parents [2] | 66 | ****** |
| * Trees | | |
| * Maximum entries [3] | 1.68 k | * |
| * Blobs | | |
| * Maximum size [4] | 13.5 MiB | * |
| | | |
| History structure | | |
| * Maximum history depth | 136 k | |
| * Maximum tag depth [5] | 1 | |
| | | |
| Biggest checkouts | | |
| * Number of directories [6] | 4.38 k | ** |
| * Maximum path depth [7] | 13 | * |
| * Maximum path length [8] | 134 B | * |
| * Number of files [9] | 62.3 k | * |
| * Total size of files [9] | 747 MiB | |
| * Number of symlinks [10] | 40 | |
| * Number of submodules | 0 | |
[1] 91cc53b0c78596a73fa708cceb7313e7168bb146
[2] 2cde51fbd0f310c8a2c5f977e665c0ac3945b46d
[3] 4f86eed5893207aca2c2da86b35b38f2e1ec1fc8 (refs/heads/master:arch/arm/boot/dts)
[4] a02b6794337286bc12c907c33d5d75537c240bd0 (refs/heads/master:drivers/gpu/drm/amd/include/asic_reg/vega10/NBIO/nbio_6_1_sh_mask.h)
[5] 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c (refs/tags/v2.6.11)
[6] 1459754b9d9acc2ffac8525bed6691e15913c6e2 (589b754df3f37ca0a1f96fccde7f91c59266f38a^{tree})
[7] 78a269635e76ed927e17d7883f2d90313570fdbc (dae09011115133666e47c35673c0564b0a702db7^{tree})
[8] ce5f2e31d3bdc1186041fdfd27a5ac96e728f2c5 (refs/heads/master^{tree})
[9] 532bdadc08402b7a72a4b45a2e02e5c710b7d626 (e9ef1fe312b533592e39cddc1327463c30b0ed8d^{tree})
[10] f29a5ea76884ac37e1197bef1941f62fda3f7b99 (f5308d1b83eba20e69df5e0926ba7257c8dd9074^{tree})
顺便提一下:如果你想要减小克隆的大小,可以使用git clone命令的参数--depth 1。
brew install git-sizer
。 - Michael Roswell如果你使用git LFS,git count-objects不会计算你的二进制文件,而只计算指向它们的指针。
如果你的LFS文件由Artifactory管理,你应该使用REST API:
git rev-list --objects --all | git cat-file --batch-check="%(objectsize) %(rest)" | cut -d" " -f1 | paste -s -d + - | bc
--all
替换为树对象(HEAD
,origin/master
等)以计算分支的大小。29941282
但是 du -sb .git/
显示 19215458 .git/
,你能解释一下这个差异吗? - SebMa