1
0
md/README.md
2026-01-05 10:39:03 +08:00

18 lines
986 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 使用 Git 克隆远程仓库部分目录
过滤掉 blob 对象,只下载 tree开启稀疏检出模式
```
git clone --filter=blob:none --sparse https://远程仓库地址.git
```
稀疏检出目标目录
```
git sparse-checkout set 你需要克隆的目录名称/
```
Git 对象数据库存储三种信息:
- blob文件内容
- tree目录结构文件夹
- commit快照、元数据、父提交
每一次 commit 都会生成一个 SHA-1 哈希值,三种数据对象通过哈希值相互引用,形成了一个 DAG有向无环图构成 Git 版本历史。但是 Git 对象数据库是不存在物理删除的,即便你将源文件删了(除非删库)。这就是为什么 commit 越多,仓库克隆也越来越慢的原因,如果被克隆的仓库存放大量文档,克隆就更慢了,因为对象数据库里的 blob 对象太大了。自 2.25+ 版本开始支持稀疏检出,可以仅克隆远程仓库部分目录,缓解问题。