有些远程仓库特别大,直接clone下来,一则耗时长,二则有可能因为网络问题中断,clone失败。所有clone远端仓库的某个文件夹是必要的,git1.7之后的版本都支持这个功能。
1.初始化:
git init
2.连接远端库:
git remote add origin url
3.启用"Sparse Checkout"功能:
git config core.sparsecheckout true
4.添加想要clone的目录:
echo “子目录路径” >> .git/info/sparse-checkout
注意:子目录路径不包含clone的一级文件夹名称:
例如库路径是:
https://A/B/C/example.git
我们想clone example下的D/E/F目录,则:
echo “D/E/F” >> .git/info/sparse-checkout
5.pull代码:
git pull origin master
或者不包含历史版本的clone:
git pull --depth 1 origin master
————————————————
请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/luo870604851/article/details/119748749
本文介绍了如何使用Git 1.7版本以上的sparse checkout功能,避免大仓库clone带来的耗时和网络风险,仅下载指定的子目录。步骤包括初始化仓库、连接远程库、启用sparse checkout、配置要克隆的目录,并演示了git pull操作。
1595

被折叠的 条评论
为什么被折叠?



