简体   繁体   中英

How do I git clone a sub-directory without cloning the entire repo anyway?

I'm a casual git user at best. I checked the other questions and they all suggest sparse checkout, but that clones my entire repo anyway, which is what I'm trying to avoid.

I have access to a very large repo, which contains a small sub-directory I need. Every time I clone the repo, it takes a loooong time to receive and takes up a massive amount of space. How do I clone just the sub-folder, and not all of the contents?

The repo is on a server that I clone using git bash a la git clone git@serverhost.com:repo.git , and I need the folder repo/subfolder . I'm on Windows.

Similarly, I needed a different branch of this same repo, which I cloned by specifying that branch only. The branch contains five small files, but it cloned the entire repo again. Can I just get the branch files?

By clone I mean, it counts the objects, compresses them, and then receives all the objects. That's the part I want to avoid; checking out the files is not my concern.

It simply is not possible. Git always clones the whole tree. --depth 0 -- branch xyz is the best you can do.

A branch also is the whole tree. There is no concept of "this revision only contains 5 files" (this is a thing in subversion, but not in git).

If you were not a casual git user, as you call yourself, but a grizzled old bear of a git expert, you could in theory hack the actual git network protocol (by writing your own low level client and talking to the repository directly), but it would probably be quite the journey...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM