查找 Git 存储库的大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8185276/
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
Find size of Git repository
提问by mschallert
What's a simple way to find the size of my Git repository?
找到我的 Git 存储库大小的简单方法是什么?
And I don't mean du -h
on the root directory of my repository. I have a lot of ignored files, so that size would be different from my total repository size. I essentially want to know how much data would be transferred upon cloning my repository.
我的意思不是du -h
在我的存储库的根目录上。我有很多被忽略的文件,因此该大小与我的总存储库大小不同。我基本上想知道在克隆我的存储库时会传输多少数据。
采纳答案by sehe
UPDATEgit 1.8.3 introduced a more efficient way to get a rough size:
git count-objects -vH
(see answer by @VonC)
更新git 1.8.3 引入了一种更有效的方法来获得粗略的大小:(
git count-objects -vH
请参阅@VonC 的回答)
For different ideas of "complete size" you could use:
对于“完整尺寸”的不同想法,您可以使用:
git bundle create tmp.bundle --all
du -sh tmp.bundle
Close (but not exact:)
关闭(但不准确:)
git gc
du -sh .git/
With the latter, you would also be counting:
对于后者,您还将计算:
- hooks
- config (remotes, push branches, settings (whitespace, merge, aliases, user details etc.)
- stashes (see Can I fetch a stash from a remote repo into a local branch?also)
- rerere cache (which can get considerable)
- reflogs
- backups (from filter-branch, e.g.) and various other things (intermediate state from rebase, bisect etc.)
- 钩子
- 配置(遥控器、推送分支、设置(空格、合并、别名、用户详细信息等)
- stashes(请参阅我可以从远程仓库中获取一个 stash 到本地分支吗?)
- rerere 缓存(可能会变得相当可观)
- 引用
- 备份(例如来自 filter-branch)和其他各种东西(来自 rebase、bisect 等的中间状态)
回答by VonC
Note that, since git 1.8.3 (April, 22d 2013):
请注意,从git 1.8.3(2013 年 4 月 22 日)开始:
"
git count-objects
" learned "--human-readable
" aka "-H
" option to show various large numbers inKi
/Mi
/GiB
scaled as necessary.
“
git count-objects
”学习“--human-readable
”又名“-H
”选项,以显示不同的大批Ki
/Mi
/GiB
缩放是必要的。
That could be combined with the -v
option mentioned by Hyman Morrisonin his answer.
这可以与Hyman莫里森在他的回答中-v
提到的选项结合起来。
git gc
git count-objects -vH
(git gc
is important, as mentioned by A-B-B's answer)
Plus (still git 1.8.3), the output is more complete:
加上(还是 git 1.8.3),输出更完整:
"
git count-objects -v
" learned to report leftover temporary packfiles and other garbage in the object store.
”
git count-objects -v
“学会了报告对象存储中剩余的临时包文件和其他垃圾。
回答by Hyman Morrison
The git command
git 命令
git count-objects -v
will give you a good estimate of the git repository's size. Without the -v flag, it only tells you the size of your unpacked files. This command may not be in your $PATH, you may have to track it down (on Ubuntu I found it in /usr/lib/git-core/, for instance).
会给你一个很好的 git 存储库大小估计。如果没有 -v 标志,它只会告诉您解压文件的大小。此命令可能不在您的 $PATH 中,您可能需要对其进行跟踪(例如,在 Ubuntu 上,我在 /usr/lib/git-core/ 中找到了它)。
From the Git man-page:
从 Git 手册页:
-v, --verbose
In addition to the number of loose objects and disk space consumed, it reports the number of in-pack objects, number of packs, disk space consumed by those packs, and number of objects that can be removed by running git prune-packed.
-v, --verbose
除了松散对象的数量和消耗的磁盘空间之外,它还报告了包内对象的数量、包的数量、这些包消耗的磁盘空间以及可以通过运行 git prune-packed 删除的对象的数量。
Your output will look similar to the following:
您的输出将类似于以下内容:
count: 1910
size: 19764
in-pack: 41814
packs: 3
size-pack: 1066963
prune-packable: 1
garbage: 0
The line you're looking for is size-pack
. That is the size of all the packed commit objects, or the smallest possible size for the new cloned repository.
您正在寻找的线路是size-pack
。这是所有打包提交对象的大小,或新克隆存储库的最小可能大小。
回答by serv-inc
You could use git-sizer
. In the --verbose
setting, the example output is (below). Look for the Total size of files
line.
你可以使用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-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})
回答by user541686
I thinkthis gives you the total list of all files in the repo history:
我认为这为您提供了回购历史记录中所有文件的总列表:
git rev-list --objects --all | git cat-file --batch-check="%(objectsize) %(rest)" | cut -d" " -f1 | paste -s -d + - | bc
You can replace --all
with a treeish (HEAD
, origin/master
, etc.) to calculate the size of a branch.
您可以替换--all
为树状 ( HEAD
、origin/master
等) 来计算分支的大小。
回答by elike
If you use git LFS, git count-objects does not count your binaries, but only the pointers to them.
如果您使用 git LFS, git count-objects 不会计算您的二进制文件,而只会计算指向它们的指针。
If your LFS files are managed by Artifactorys, you should use the REST API:
如果您的 LFS 文件由 Artifactorys 管理,您应该使用 REST API:
- Get the www.jfrog.com API from any search engine
- Look at Get Storage Summary Info
- 从任何搜索引擎获取 www.jfrog.com API
- 查看获取存储摘要信息
回答by RMPR
If the repository is on GitHub, you can use the open source Android app Octodroidwhich displays the size of the repository by default.
如果存储库在GitHub 上,您可以使用开源 Android 应用Octodroid,它默认显示存储库的大小。
For example, with the mptcprepository:
例如,使用mptcp存储库:
Disclaimer: I didn't create Octodroid.
免责声明:我没有创建 Octodroid。