这里以 https://github.com/elastic/built-docs 项目举例
- 我们只需要下载
html/en/elasticsearch/reference/8.x
以及html/static
这两个文件夹下的内容。 - 首先初始化一个本地空仓库:
git init elastic-docs && cd elastic-docs
- 启用稀疏检出:
git config core.sparseCheckout true
- 指定目标目录
echo "html/en/elasticsearch/reference/8.x/" >> .git/info/sparse-checkout echo "html/static/" >> .git/info/sparse-checkout
- 添加远程仓库
git remote add origin git@github.com:elastic/built-docs.git
- 设置对象过滤
git config --local remote.origin.promisor true git config --local remote.origin.partialclonefilter "blob:none tree:0"
- 定位到最新提交
git fetch --depth=1 --filter=tree:0 origin master
- 拉区代码
git checkout FETCH_HEAD