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

前端 未结 18 2889
时光说笑
时光说笑 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 05:15

    Here's a shell script I wrote for the use case of a single subdirectory sparse checkout

    coSubDir.sh

    localRepo=$1
    remoteRepo=$2
    subDir=$3
    
    
    # Create local repository for subdirectory checkout, make it hidden to avoid having to drill down to the subfolder
    mkdir ./.$localRepo
    cd ./.$localRepo
    git init
    git remote add -f origin $remoteRepo
    git config core.sparseCheckout true
    
    # Add the subdirectory of interest to the sparse checkout.
    echo $subDir >> .git/info/sparse-checkout
    
    git pull origin master
    
    # Create convenience symlink to the subdirectory of interest
    cd ..
    ln -s ./.$localRepo/$subDir $localRepo
    

提交回复
热议问题