天天看點

git pull 指定某一個檔案或檔案夾

1、要解決的問題

預設情況下,git pull 操作會把遠端倉庫的所有最新資料更新到本地。

但是,如果你隻想更新指定的某一個檔案或檔案夾,該怎麼操作呢?

2、git 隻 pull 某一個檔案/夾

  • 設定

    core.sparsecheckout

    為 true
    $ git config core.sparsecheckout true
               
    • core.sparsecheckout

      用于控制是否允許設定pull指定檔案/夾,true為允許。
    • 此方法适用于 Git1.7.0 以後版本,之前的版本沒有這個功能。
  • .git/info/sparse-checkout

    檔案中(如果沒有則建立)添加指定的檔案/夾
  • 最後,拉取想要的分支即可實作checkout指定檔案/夾。
    $ git pull origin master