git 克隆 github 项目的一部分

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1618025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:15:45  来源:igfitidea点击:

clone parts of a github project

gitgithubtortoisegit

提问by Dennis

Possible Duplicate:
Is there any way to clone a git repository's sub-directory only?

可能的重复:
有没有办法只克隆 git 存储库的子目录?

I'm trying to clone parts of a github project but I can only get the root folder. This is the first time im trying to use github and I just installed tortoisegit, im used to svn and cvs where you could just take a folder you wanted to checkout, but it seems git only got a .git file in the root folder so im not sure what to do.

我正在尝试克隆 github 项目的一部分,但我只能获取根文件夹。这是我第一次尝试使用 github,我刚刚安装了 tortoisegit,我曾经使用 svn 和 cvs,您可以在其中取出您想要结帐的文件夹,但似乎 git 在根文件夹中只有一个 .git 文件,所以我不知道该怎么办。

回答by JasonSmith

There is the subtree merge.

有子树合并。

But here is an easier but partial solution that perhaps is good enough for your needs. Just fork and periodically merge back.

但这里有一个更简单但部分的解决方案,可能足以满足您的需求。只需fork 并定期合并回来

  1. Fork (clone) the repository
  2. Remove parts you do not need and move the sub-folder to where you do need
  3. Commit
  1. 分叉(克隆)存储库
  2. 删除您不需要的部分并将子文件夹移动到您需要的地方
  3. 犯罪

In the future, when you want to sync back up with the upstream Git code, just merge it with your fork. The files which you kept will sync back up with those from upstream, and you might have some small cleanups to do which are easy to see from git status.

将来,当您想与上游 Git 代码同步备份时,只需将其与您的 fork 合并即可。您保留的文件将与来自上游的文件同步备份,您可能需要进行一些小的清理工作,从git status.

回答by Chris Johnsen

In the Git community what you want is called a “partial checkout”. It is not currently supported in Git, but it comes up every once in a while on the mailing list. Git has bits and pieces of the internals needed to support partial checkout, but there is no easy way to make use of them as a user. I would guess that Git will eventually be able to do partial checkouts, but it might be a while before it happens.

在 Git 社区中,您想要的称为“部分签出”。Git 目前不支持它,但它每隔一段时间就会出现在邮件列表中。Git 具有支持部分结账所需的零碎内部结构,但作为用户,没有简单的方法来使用它们。我猜想 Git 最终将能够进行部分结帐,但可能需要一段时间才能实现。

In addition to jhs's answers(subtree merge; rm, mv, commit, merge), there is also a third-party ‘subtree' commandthat might help make it easier to work with partial checkouts. Though that is not its main goal, so it is not obvious how you might use it to work with a partial checkout. If you already know Git well enough, you could work it out, but if you are new to Git, this subtree command will likely be fairly opaque.

除了jhs 的答案(子树合并;rm、mv、提交、合并)之外,还有一个第三方“子树”命令可能有助于更轻松地处理部分结帐。尽管这不是它的主要目标,因此如何使用它来处理部分结帐并不明显。如果您已经足够了解 Git,则可以解决它,但如果您是 Git 新手,则此子树命令可能相当不透明。

Finally, if all you want to do is download the latest files, you might be able to use git archiveto download a tar file of a specific branch or tag (or any commit-ish). This may not work with GitHub (it depends on server configuration), I have not checked. Even if it does not work directly, you could clone to your own ‘bare', mirror repo and then pull (subtree) archives from that.

最后,如果您只想下载最新的文件,您可以使用git archive下载特定分支或标签(或任何 commit-ish)的 tar 文件。这可能不适用于 GitHub(这取决于服务器配置),我没有检查过。即使它不能直接工作,您也可以克隆到您自己的“裸”、镜像存储库,然后从中提取(子树)档案。

回答by Xiong Chiamiov

This isn't really something that you do in git. Remember, you're using a DVCS, so you're pulling down entire repository history - what is supposed to happen to the commits that change files outside the directory you're pulling down?

这实际上不是您在 git 中所做的事情。请记住,您正在使用 DVCS,因此您正在拉取整个存储库历史记录 - 更改您拉取的目录外的文件的提交应该会发生什么?

If a project is sufficiently large, then the maintainer of whatever repo you're cloning should use submodules to divide up the sections, so that developers can only pull down the areas they want to work on.

如果一个项目足够大,那么你克隆的任何 repo 的维护者都应该使用子模块来划分部分,这样开发人员只能下拉他们想要工作的区域。

Git (well, DVCSs in general) is not designed for endusers so much as it is for developers. I find git (especially in combination with github) to be incredibly helpful for coding. If there's a project on github that I want to contribute to, I just fork it, pull it down, hackhackhack, push up, and send a pull request, easypeasy, rather than making a checkout, hacking, creating a diff, trying to find where to email it to, and hoping that the diff doesn't break before the developers get around to merging it in.

Git(嗯,一般来说,DVCS)不是为最终用户设计的,而是为开发人员设计的。我发现 git(尤其是与 github 结合使用)对编码非常有帮助。如果我想为 github 上的一个项目做出贡献,我只是将它分叉,将其拉下来,hackhackhack,push up,然后发送拉取请求,easypeasy,而不是进行结帐、hacking、创建差异、试图找到将其通过电子邮件发送到何处,并希望在开发人员开始合并之前差异不会中断。

Git as a whole is certainly more complicated than svn, but that's because coding is a complicated process. The centralized VCS workflow is incredibly painful for me, because I was raised on DVCSs, and I'm not allowed to do all sorts of things that I'm used to doing. So, yes, it will be more complicated to use git vs. svn if you do the same things, but the advantage is that there are somanymore things that you can do. Git was developed for linux kernel development, and it shows.

Git 整体上肯定比 svn 复杂,但那是因为编码是一个复杂的过程。集中式 VCS 工作流程对我来说非常痛苦,因为我是在 DVCS 上长大的,我不能做我习惯做的各种事情。所以,是的,这将更加复杂,如果你做同样的事情,使用git与SVN,但好处是,有这么更多的东西,你可以做。Git 是为 linux 内核开发而开发的,它显示了。