Git: How do I clone a subdirectory only of a Git repository?

前端 未结 18 2948
时光说笑
时光说笑 2020-11-21 04:33

I have my Git repository which, at the root, has two sub directories:

/finisht
/static

When this was in SVN, /finisht was chec

18条回答
  •  醉酒成梦
    2020-11-21 04:58

    You can combine the sparse checkout and the shallow clone features. The shallow clone cuts off the history and the sparse checkout only pulls the files matching your patterns.

    git init 
    cd 
    git remote add origin 
    git config core.sparsecheckout true
    echo "finisht/*" >> .git/info/sparse-checkout
    git pull --depth=1 origin master
    

    You'll need minimum git 1.9 for this to work. Tested it myself only with 2.2.0 and 2.2.2.

    This way you'll be still able to push, which is not possible with git archive.

提交回复
热议问题