跳到主内容
博客oldsaltfish
博客

git克隆部分文件

更新于 2025-06-25 09:48

前言

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

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

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

解决

shell
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

评论

正在加载评论