How to clone or download a repository subfolder in git?
某草草
某草草 2017-05-02 09:39:03
0
3
974

The entire repository is huge. I am only interested in one of the folders and do not want to clone the entire project repository.

某草草
某草草

reply all(3)
PHPzhong

The way Git stores files is different from CVS/SVN. When you clone a git repository, you clone all the data in the repository, rather than just the few files you currently need.

Git 1.7.9.5 and later versions allow exporting a single file of a remote repository, such as

git archive --remote=ssh://host/pathto/repo.git HEAD README.md # 导出 README.md 这个文件

If you have performed a clone operation before and the file you need is in the commit history, you can use the git log command to find the hash value of the commit and then execute the following command:

git checkout hash-id path-to-file

Specially, if your code is a public project, you can also do this:

Applicable to Coding

wget https://coding.net/u/user/p/project/git/raw/master/README

For GitHub

wget https://raw.githubusercontent.com/user/project/master/README
PHPzhong

My solution:
Take the https://github.com/geekhac/to... subdirectory as an example:

git init todomvc && cd todomvc

git config core.sparsecheckout true //Set to allow cloning subdirectories

echo '/examples/react/*' >> .git/info/sparse-checkout //Set the subdirectory path of the warehouse to be cloned

git remote add origin https://github.com/geekhac/to...

git pull origin master

Ty80

Enter the folder you are interested in and execute git init初始化这个文件,在cloneto your local area

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template