克隆GitHub仓库中的一个文件夹
要只克隆GitHub仓库中的一个文件夹,你可以使用 git sparse-checkout
功能。以下是具体步骤:
-
克隆仓库(使用
--no-checkout
选项,避免下载所有内容):git clone --no-checkout <仓库地址>
-
进入克隆的目录:
cd <仓库名>
-
启用稀疏检出:
git sparse-checkout init --cone
-
设置要检出的文件夹:
git sparse-checkout set <文件夹路径>
-
检出文件夹的内容:
git checkout <分支名>
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar
$ git init
Initialized empty Git repository in D:/edgeDownload/resource/pits/peachstar/.git/
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar (master)
$ git clone --no-checkout https://github.com/THU-WingTecher/PeachStar.git
Cloning into 'PeachStar'...
remote: Enumerating objects: 7427, done.
remote: Total 7427 (delta 0), reused 0 (delta 0), pack-reused 7427 (from 1)
Receiving objects: 100% (7427/7427), 77.26 MiB | 1.58 MiB/s, done.
Resolving deltas: 100% (2083/2083), done.
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar (master)
$ cd PeachStar/
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar/PeachStar (master)
$ git sparse-checkout init --cone
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar/PeachStar (master|SPARSE)
$ git sparse-checkout set peach-3.0.202-source/samples
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar/PeachStar (master|SPARSE)
$ git sparse-checkout set peach-3.0.202-source/samples
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar/PeachStar (master|SPARSE)
$ git checkout
Your branch is up to date with 'origin/master'.
fuyul@mine MINGW64 /d/edgeDownload/resource/pits/peachstar/PeachStar (master|SPARSE)
$