# 創建一個與要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