Is possible clone only a folder from remote repository?

本小妞迷上赌 提交于 2019-12-08 07:04:29

问题


I want download only 2 folders from remote git repository. In this case is the ubuntu kernel git repository.
Download all kernel is a waste of time and bandwidth if I only want 2 folders.
Is there any way to do this with git?


回答1:


No you can't create a partial clone




回答2:


No, not in the way you're asking. But you can do one of these:

  1. download a tarball -- the repository's web-ui should offer such an option, otherwise you can use git archive (man page, google and SO will help you with its usage); or
  2. do a shallow clone, using the --depth switch; this will download only the given number of commits, so you don't get the whole history. The git clone manpage has more details about it.



回答3:


It seems Git CANNOT implement this.

I thought "Sparse Checkout" will works, but as @ HolgerJust said:

This will still download the full remote repository. It just doesn't checkout all the files into the working copy, but they are still available in the local index.

He's right.


Yes, you can. You can use Sparse Checkout.

Here's a simple example:

$ mkdir destinationFolder
$ cd destinationFolder
$ git init
$ git remote add origin git@github.com:Kjuly/iPokeMon.git
$ git config core.sparseCheckout true
$ echo 'Pokemon/Models/*' > .git/info/sparse-checkout
... echo more if you need
$ git pull origin dev

And finally, you'll get files:

destinationFolder
- Pokemon
- - Models



来源:https://stackoverflow.com/questions/14526760/is-possible-clone-only-a-folder-from-remote-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!