# 创建一个与要clone的仓库同名或不同命的目录
$ mkdir models
$ cd models
$ git init #初始化
$ git remote add origin https://github.com/tensorflow/models.git # 增加远端的仓库地址
$ git config core.sparsecheckout true # 设置Sparse Checkout 为true
$ echo "research/deeplab" >> .git/info/sparse-checkout # 将要部分clone的目录相对根目录的路径写入配置文件
$ git pull origin master #pull下来代码
如果只想保留最新的文件而不要历史版本的文件,上例最后一行可以用git pull --dpeth 1命令,即“浅克隆”:
$ git pull --depth 1 origin master
进仓库目录检查下,发现只有research/deeplab这个路径,操作完成。
# 为了启用"Sparse Checkout"功能,需要将git选项core.sparsecheckout为true:
$ git config core.sparsecheckout true