Partial Clone
一句话解释
部分克隆下载仓库结构但省略部分文件内容(blob),按需拉取。
用大白话说
部分克隆(--filter)下载仓库的提交、树和标签,但按过滤器省略部分文件内容(blob)。当你后来 checkout 或 diff 一个内容缺失的文件时,Git 按需仅拉取那个 blob。这显著降低大仓库的初始克隆时间与磁盘占用。最常见过滤器是 --filter=blob:none,省略所有文件内容——你得到完整历史结构但无文件体,直到需要。--filter=tree:0 连树对象也省略,更激进。服务端须支持(GitHub、GitLab 支持)。部分克隆与稀疏检出搭配:不带 blob 克隆,再仅物化你需要的目录。这是处理庞大 monorepo 的现代方式——只为实际读取的内容付费。代价是首次访问每个文件时的小延迟,因其 blob 被拉取。
示例
bash
# Clone without any file contents (blobs)
git clone --filter=blob:none https://github.com/org/huge-repo.git
cd huge-repo
# The history is complete, but file contents are fetched on demand
git log --oneline # works — no blobs needed
cat README.md # triggers a fetch of README.md's blob
# Combine with sparse checkout for maximum efficiency
git sparse-checkout init --cone
git sparse-checkout set packages/web--filter=blob:none 克隆时跳过所有文件内容。读文件触发按需拉取该 blob。配合稀疏检出,只下载你用的。
相关术语
相关资源
相关课程
- Git 进阶
学习部分克隆。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。