git 分支和标签如何存储在磁盘中? [英] How git branches and tags are stored in disks?
问题描述
我最近在工作中检查了我的一个 git 存储库,它有超过 10,000 个分支和超过 30000 个标签.新克隆后的 repo 总大小为 12Gigs.我确信没有理由拥有 10000 个分支机构.所以我相信它们会在磁盘中占据相当大的空间.所以,我的问题如下
I recently checked one of my git repositories at work, which had more than 10,000 branches and more than 30000 tags. The total size of the repo, after a fresh clone is 12Gigs. I am sure there is no reason to have 10000 branches. So I believe they would occupy considerable amount of space in the disks. So, my questions are as follows
- 分支和标签如何存储在磁盘中,例如使用什么数据结构,每个分支存储什么信息?
- 如何获取有关分支机构的元数据?比如那个分支创建的时候,这个分支的大小是多少.
推荐答案
所有 git 引用(分支、标签、注释、存储等)都使用相同的系统.它们是:
All git references (branches, tags, notes, stashes, etc) use the same system. These are:
- 引用本身,以及
- 引用日志"
Reflogs 根据引用名称存储在 .git/logs/refs/
中,但有一个例外:HEAD
的 reflogs 存储在 .git/logs/HEAD
而不是 .git/logs/refs/HEAD
.
Reflogs are stored in .git/logs/refs/
based on the reference-name, with one exception: reflogs for HEAD
are stored in .git/logs/HEAD
rather than .git/logs/refs/HEAD
.
引用要么是松散的",要么是打包的".打包的 refs 位于 .git/packed-refs
中,这是一个包含 (SHA-1, refname) 对的平面文件,用于简单的 refs,以及带注释标签的额外信息.松散"的参考在 .git/refs/name
中.这些文件包含原始 SHA-1(可能是最常见的),或文字字符串 ref:
后跟符号引用的另一个引用的名称(通常仅用于 HEAD
但你可以制作其他人).符号引用没有打包(或者至少,我似乎无法做到这一点:-)).
References come either "loose" or "packed". Packed refs are in .git/packed-refs
, which is a flat file of (SHA-1, refname) pairs for simple refs, plus extra information for annotated tags. "Loose" refs are in .git/refs/name
. These files contain either a raw SHA-1 (probably the most common), or the literal string ref:
followed by the name of another reference for symbolic refs (usually only for HEAD
but you can make others). Symbolic refs are not packed (or at least, I can't seem to make that happen :-) ).
打包标签和空闲"分支头(那些没有被主动更新的)可以节省空间和时间.您可以使用 git pack-refs
来做到这一点.但是,git gc
会为你调用 git pack-refs
,所以一般你不需要自己做.
Packing tags and "idle" branch heads (those that are not being updated actively) saves space and time. You can use git pack-refs
to do this. However, git gc
invokes git pack-refs
for you, so generally you don't need to do this yourself.
这篇关于git 分支和标签如何存储在磁盘中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!