git克隆部分文件

前言

我遇到一个问题,某个目录我作为发布目录,但是他又不是特别稳定,如果每次都作为release太过麻烦。
因此衍生了标题的需求。

git clone --no-checkout https://github.com/user/repo.git
cd repo
git sparse-checkout set dir/subdir
git checkout main

这个方案依然下载了全部文件。

解决

git clone --depth 1 --filter=blob:none --sparse https://github.com/user/repo.git
cd repo
# 比如需要dist文件夹,执行到这里才会进行下载操作
git sparse-checkout set dist

不过这个方法在clone阶段就会下载readme和.gitignore,也算不上完美。
image

posted @ 2025-06-25 09:47  魂祈梦  阅读(30)  评论(0)    收藏  举报