找到git repo的大小

问题描述 投票:246回答:5

找到我的git存储库大小的简单方法是什么?而且我不是指我的回购根目录上的du -h。我有很多被忽略的文件,因此大小与我的总回购大小不同。我基本上想知道在克隆我的回购时会传输多少数据。

git filesize
5个回答
231
投票

UPDATE git 1.8.3引入了一种更有效的方法来获得粗略的大小:git count-objects -vH(请参阅@VonC的回答)

对于“完整尺寸”的不同想法,您可以使用:

git bundle create tmp.bundle --all
du -sh tmp.bundle

关闭(但不完全:)

git gc
du -sh .git/

对于后者,你也会指望:

  • 挂钩
  • config(远程,推送分支,设置(空白,合并,别名,用户详细信息等)
  • stashes(另见Can I fetch a stash from a remote repo into a local branch?
  • rerere缓存(可以获得相当大的收益)
  • reflogs
  • 备份(来自filter-branch,例如)和其他各种事物(来自rebase,bisect等的中间状态)

214
投票

请注意,因为git 1.8.3 (April, 22d 2013)

git count-objects”学会了“--human-readable”又名“-H”选项,以显示Ki / Mi / GiB中的各种大数字,并根据需要进行缩放。

这可以与-vJack Morrison中提到的his answer选项相结合。

git gc
git count-objects -vH

git gc很重要,正如A-B-Banswer所提到的那样)

加(仍然是git 1.8.3),输出更完整:

git count-objects -v”学会了在对象商店报告剩余的临时包装文件和其他垃圾。


103
投票

git命令

git count-objects -v

将为您提供git存储库大小的良好估计。如果没有-v标志,它只会告诉您解压缩文件的大小。这个命令可能不在你的$ PATH中,你可能需要跟踪它(在Ubuntu上我发现它在/ usr / lib / git-core /中)。

从Git手册页:

-v, - verbose

除了消耗的松散对象和磁盘空间的数量之外,它还报告包内对象的数量,包的数量,这些包消耗的磁盘空间以及通过运行git prune-packed可以删除的对象的数量。

您的输出将类似于以下内容:

count: 1910
size: 19764
in-pack: 41814
packs: 3
size-pack: 1066963
prune-packable: 1
garbage: 0

你要找的那条线是size-pack。这是所有打包的提交对象的大小,或者是新克隆的存储库的最小可能大小。


1
投票

如果你使用git LFS,git count-objects不会计算你的二进制文件,只会指向它们的指针。

如果您的LFS文件由Artifactorys管理,则应使用REST API:

  • 从任何搜索引擎获取www.jfrog.com API
  • 查看获取存储摘要信息

1
投票

你可以使用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})

1
投票

我想这会为您提供repo历史记录中所有文件的总列表:

git rev-list --objects --all | git cat-file --batch-check="%(objectsize) %(rest)" | cut -d" " -f1 | paste -s -d + - | bc

您可以用树木(--allHEAD等)替换origin/master来计算分支的大小。

© www.soinside.com 2019 - 2024. All rights reserved.