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

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

    For other users who just want to download a file/folder from github, simply use:

    svn export /trunk/
    

    e.g.

    svn export https://github.com/lodash/lodash.com/trunk/docs
    

    (yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)

    Courtesy: Download a single folder or directory from a GitHub repo

    Important - Make sure you update the github URL and replace /tree/master/ with '/trunk/'.

    As bash script:

    git-download(){
        folder=${@/tree\/master/trunk}
        folder=${folder/blob\/master/trunk}
        svn export $folder
    }
    

    Note This method downloads a folder, does not clone/checkout it. You can't push changes back to the repository. On the other hand - this results in smaller download compared to sparse checkout or shallow checkout.

提交回复
热议问题