简体   繁体   English

如何使用 Git 从存储库中只下载一个子文件夹?

[英]How to download only a sub folder from a repository using Git?

My experience with git consists of about 4 hours reading github and bitbucket help pages and setting up my local repositories and ssh keys on my computer, so please excuse me if the answer is rather obvious.我对 git 的体验包括大约 4 小时阅读 github 和 bitbucket 帮助页面,并在我的计算机上设置我的本地存储库和 ssh 密钥,所以如果答案很明显,请原谅。

I will use 538's github as an example to ask my question.我就以538的github为例来问我的问题。

On my local computer, once I initialize my git folder and have been added to the list of contributors, I know I can download a local copy of the whole folder.在我的本地计算机上,一旦我初始化了我的 git 文件夹并将其添加到贡献者列表中,我就知道我可以下载整个文件夹的本地副本。

However for example sake, lets say I was only interested in the nba-draft-2015 subdirectory.但是为了举例,假设我只对nba-draft-2015子目录感兴趣。

From reading How to pull specific directory with git and How to git-pull all but one folder it appears that there is a way to just download the sub directory folder.从阅读How to pull specific directory with gitHow to git-pull all but one folder看来有一种方法可以只下载子目录文件夹。

Assuming the location or my repo locally is ~/repo, could someone give me what commands I would type into git for this specific example with the 538 data?假设位置或我的本地回购是 ~/repo,有人可以告诉我我将在 git 中输入什么命令,用于这个包含 538 数据的特定示例吗?

I have read the other SO pages and didn't completely understand the links and answers, so I think an example with the 538 page would help best illustrate it for me.我已经阅读了其他 SO 页面并且没有完全理解链接和答案,所以我认为 538 页面的示例最能帮助我说明它。

Well looking at that repository there are only two files,so if you just wanted those two files you could just download them, or use the steps from your links, this might work too (I could not personally get it working). 在该存储库中,只有两个文件,因此,如果您只想要这两个文件,则可以下载它们,或者使用链接中的步骤, 也可能起作用(我个人无法使其工作)。

I would pull a shallow clone git clone --depth 1 https://github.com/fivethirtyeight/data.git , it only takes a few seconds for me, because it doesn't get all the history, just the most recent change. 我会拉一个浅层克隆git clone --depth 1 https://github.com/fivethirtyeight/data.git ,对我来说只需要几秒钟,因为它不能获取所有历史记录,而只是最新的变化。

However, If you want to be a contributor I don't think you can just pull a part of it, I could be wrong though. 但是,如果您想成为一名贡献者,我认为您不能仅仅承担一部分,但是我可能是错的。

Reading the answer at https://stackoverflow.com/a/2303645/8395964 , seems that it is not possible:https://stackoverflow.com/a/2303645/8395964阅读答案,似乎是不可能的:

Note that sparse checkouts still require you to download the whole repository, even though some of the files Git downloads won't end up in your working tree.请注意,稀疏签出仍然需要您下载整个存储库,即使某些文件 Git 下载不会最终出现在您的工作树中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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