根據網上資料整理而來,git 1.7版本后支持的sparse checkout特性,可以指定需要checkout的目錄或者文件。
# 設置允許git克隆子目錄 git config core.sparsecheckout true # 創建本地空repo git init myRepo && cd myRepo # 設置要克隆的倉庫的子目錄路徑, “*” 是通配符,“!” 是反選 echo deployment >> .git/info/sparse-checkout # 設置遠程倉庫地址 git remote add origin ssh://github.com/abc.git # 用 pull 來拉取代碼 git pull origin master ############################# # 如果需要添加目錄,就增加sparse-checkout的配置,再checkout master echo another_folder >> .git/info/sparse-checkout git checkout master
后來上面方法遇到錯誤
error: Sparse checkout leaves no entry on working directory
,又找到另一種方法如下。最后發現,如果在shell里執行,sparse-checkout 里的路徑需要最后加*,但是如果是git-prompt,則可以不需要最后的/*.
git clone -n https://github.com/tensorflow/models cd tensorflow git config core.sparsecheckout true echo official/resnet/* >> .git/info/sparse-checkout git checkout master