Git 克隆部分文件

  1. 使用 sparse-checkout (推荐)
git clone \
    -b master \
    --depth=1 \
    --filter=blob:none \
    --sparse \
    <repo-url> \
    <repo-name>
cd <repo-name>
git sparse-checkout set <file-path>

<repo-url> 为仓库地址;<repo-name>为项目名称;<file-path>为需要克隆的文件。

使用 git sparse-checkout list 可查看检出的文件。

  1. 使用 --no-checkout 标签
git clone \
    -b master \
    --depth=1 \
    --filter=blob:none \
    --no-checkout \
    <repo-url> \
    <repo-name>
cd <repo-name>
git checkout master -- <file-path>

此方法会逐个拉取文件,若文件数量多拉取会非常耗时。仅需克隆少量文件时可使用。


参考:

https://git-scm.com/docs/git-sparse-checkout

posted @ 2022-10-31 19:02  夏目有三三  阅读(613)  评论(0)    收藏  举报