git只克隆倉庫某個目錄

# 創建一個與要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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章