【问题标题】:How to import a specific project from github如何从 github 导入特定项目
【发布时间】:2020-08-03 17:12:14
【问题描述】:

如何从 github 导入特定项目?我不想克隆整个存储库 我只想克隆存储库的一部分。

例如这个网址https://github.com/eugenp/tutorials 有很多项目,但我只想克隆 spring-boot-crud project 。 这是 spring-boot-crud 项目的 url。 https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-crud

谢谢。

【问题讨论】:

  • 我已经编辑了我的答案以包含一个 Eclipse 示例。

标签: eclipse github


【解决方案1】:

您可以查看git sparse-checkout:该命令仅用于检出 Git 存储库的一部分。这假设是最新的 Git 2.26。
我的意思是 Git-core,如 Git SCM,而不是 Egit(它不支持新的 sparse-checkout 命令)

即使该命令是新的并且仍处于试验阶段,它在您的情况下应该很有用。

git clone --no-checkout /url/a/repo
cd repo
git sparse-checkout init --cone
git sparse-checkout set spring-boot-modules/spring-boot-crud

然后在你的 Eclipse 中打开相关的项目。

在 Git 存储库中创建一个项目(.project,在你的存储库的根文件夹中)

这会给你:

git clone -n https://github/git/git git2
cd git2
git sparse-checkout init
git sparse-checkout set Documentation

此时,您已拥有存储库 git/git检出了文件夹 Documentation(其他所有内容均不在工作树中)

# create an empty project in C:\path\to\git2 in Eclipse

如您所见,所有其他未检出的文件都不会显示在 Git 暂存视图中。仅列出当前签出和修改的那些。

第一步必须在命令行中完成,因为 JGit 不支持 sparse-checkout 指令(参见 but 383772change 33

【讨论】:

  • 这会克隆整个存储库并仅检出一个文件夹,对吗? latest Git 你的意思是 git-core(命令行 Git),而不是 EGit,对吧?请更清楚地表明您正在谈论的工具与所要求的工具不同。您是否测试过这两种工具是否以这种方式协同工作(显示历史记录、提交、推送等)?
  • @howlger 是的,git-core。正确填充工作树后,您可以在 Eclipse 中打开项目。
  • 不错。未签出的文件怎么办?在 Git Staging 视图中,它们会显示为已删除还是被忽略?
  • @howlger 不确定。甚至 JGit 似乎也不支持稀疏结帐:bugs.eclipse.org/bugs/show_bug.cgi?id=383772git.eclipse.org/r/#/c/110964/33
猜你喜欢
  • 2017-12-09
  • 2015-06-25
  • 1970-01-01
  • 2011-01-18
  • 1970-01-01
  • 2017-01-05
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多