Windows git 利用sparse-checkout 只下载子文件夹

来源:互联网 发布:信鸽软件鑫 编辑:程序博客网 时间:2024/06/05 09:33

因为全部项目文件太大,而且只对某几个子文件夹感兴趣,印象中git有个sparse-checkout的功能,因此实践一番,遇到了一些问题,以Tensorflow Models 为例分享一下。

Segmentfault的分享

按照爱睡觉的小猫咪 答案所述

git init models && cd modelsgit config core.sparsecheckout true //设置允许克隆子目录echo official/resnet/* >> .git/info/sparse-checkout //设置要克隆的仓库的子目录路径git remote add origin https://github.com/tensorflow/modelsgit pull origin master 

这种方法的git pull origin master存疑,我遇到过error: Sparse checkout leaves no entry on the working directory的错误,按照下一方法的git checkout master则没有出现错误。

StackOverflow的分享

git clone -n https://github.com/tensorflow/modelscd tensorflowgit config core.sparsecheckout trueecho official/resnet >> .git/info/sparse-checkoutgit checkout master

值得注意的是,无论哪种方法都需要下载.git文件夹,这是git的元数据存储。 大项目的.git元数据通常也比较庞大,比如Tensorflow 元数据133.31MB,Models 的元数据243.66MB,下载依然要不少时间。
当想追加子文件夹时,继续echo official/mnist/* >> .git/info/sparse-checkoutgit checkout master 即可。

如有错误或建议,欢迎交流。

原创粉丝点击