克隆 github 项目的部分内容
可能的重复:
有没有办法克隆 git仅存储库的子目录?
我正在尝试克隆 github 项目的部分内容,但只能获取根文件夹。 这是我第一次尝试使用github,我刚刚安装了tortoisegit,我习惯了svn和cvs,你可以在其中获取你想要签出的文件夹,但似乎git在根文件夹中只有一个.git文件,所以我不知道该怎么办。
Possible Duplicate:
Is there any way to clone a git repository’s sub-directory only?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有子树合并。
但这里有一个更简单但部分的解决方案,也许足以满足您的需求。只需分叉并定期合并回来。
将来当您想要与上游 Git 代码同步备份时,只需将其与您的分叉合并即可。您保留的文件将与上游的文件同步备份,并且您可能需要进行一些小的清理工作,这些清理工作很容易从
git status
中看到。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.
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 社区中,您想要的称为“部分签出”。目前 Git 不支持它,但它偶尔会出现在邮件列表中。 Git 具有支持部分签出所需的一些内部结构,但作为用户没有简单的方法来使用它们。我猜测 Git 最终将能够进行部分签出,但可能需要一段时间才能实现。
除了jhs的答案(子树合并;rm,mv 、提交、合并),还有第三方“子树”命令可能会有所帮助使部分结帐工作变得更容易。尽管这不是它的主要目标,所以如何使用它来进行部分结账还不清楚。如果您已经足够了解 Git,您可以解决它,但如果您是 Git 新手,这个子树命令可能会相当不透明。
最后,如果您只想下载最新文件,您可以 使用
git archive
下载特定分支或标记(或任何提交)的 tar 文件。这可能不适用于 GitHub(这取决于服务器配置),我没有检查过。即使它不能直接工作,您也可以克隆到您自己的“裸”、镜像存储库,然后从中提取(子树)档案。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.
In addition to jhs's answers (subtree merge; rm, mv, commit, merge), there is also a third-party ‘subtree’ command that 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.
Finally, if all you want to do is download the latest files, you might be able to use
git archive
to 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 中所做的事情。请记住,您使用的是 DVCS,因此您要拉取整个存储库历史记录 - 更改您拉取的目录之外的文件的提交会发生什么情况?
如果项目足够大,那么您要克隆的任何存储库的维护者都应该使用子模块来划分各个部分,以便开发人员只能拉下他们想要处理的区域。
Git(嗯,一般来说是 DVCS)并不是为最终用户设计的,而是为开发人员设计的。我发现 git(尤其是与 github 结合使用)对于编码非常有帮助。如果 github 上有一个我想贡献的项目,我只需分叉它,将其拉下来,hackhackhack,push up,然后发送拉取请求,easypeasy,而不是进行结账,黑客攻击,创建差异,试图找到将其通过电子邮件发送到哪里,并希望在开发人员开始将其合并之前,差异不会被破坏。Git
作为一个整体肯定比 svn 更复杂,但这是因为编码是一个复杂的过程。集中式 VCS 工作流程对我来说非常痛苦,因为我是在 DVCS 中长大的,而且我不被允许做我习惯做的各种事情。所以,是的,如果你做同样的事情,使用 git 与 svn 会更复杂,但优点是你可以做更多的事情。做。 Git 是为 Linux 内核开发而开发的,它表明了这一点。
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?
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.
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 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 so many more things that you can do. Git was developed for linux kernel development, and it shows.