简体   繁体   English

如何使现有回购成为 GitHub 上新回购的子回购?

[英]How to make an existing repo a sub repo of a new repo on GitHub?

I have taken some challenges on frontendmentor and created these repositories on GitHub:我在frontendmentor上接受了一些挑战,并在 GitHub 上创建了这些存储库:

FEM-calculator-project FEM-计算器-项目

FEM-Landing-page FEM-着陆页

Is it possible to move these two repositories into a new one named:是否可以将这两个存储库移动到一个名为:

frontendmentor-challenges前端或挑战

I've been stuck with this for a while now.我已经坚持了一段时间了。 Is there a way around it?有办法解决吗?

I have no knowledge in front- and backend so my answer will be based on my knowledge in Git. You can add one repo as a submodule inside the other repo.我对前端和后端一无所知,所以我的回答将基于我在 Git 中的知识。您可以将一个存储库作为子模块添加到另一个存储库中。 After doing that you can navigate to the submodule and deal with it as normal repo.这样做之后,您可以导航到子模块并将其作为普通回购处理。

so for example, given that you have cloned the frontendmentor-challenges now navigate to it and add FEM-calculator-project and FEM-Landing-page as submodules inside frontendmentor-challenges .因此,例如,假设您已经克隆了frontendmentor-challenges现在导航到它并将FEM-calculator-projectFEM-Landing-page作为子模块添加到frontendmentor-challenges中。

To add submodule:添加子模块:

$ git submodule add <remote_url>  /*of the repo that you want to add as submodule*/  
$ git commit -m "comment"
$ git push

There is alot to know about submodules, like updating the submodule and so on.有很多关于子模块的知识,比如更新子模块等等。 I hope this works for you:)我希望这对你有用:)

Sometime, we want to add some repository (child repo) in a repository (parent repo), but want to manage child repos independently.有时,我们想在一个仓库(父仓库)中添加一些仓库(子仓库),但又想独立管理子仓库。

That's when we need submodule, you can refer first那就是我们需要子模块的时候,你可以先参考

add child repo to parent repo (same clone), you can check cat.git/config .将子仓库添加到父仓库(同一个克隆),你可以检查cat.git/config Then, you can add, commit normally.然后,您可以正常添加,提交。

git submodule add <link child repos>

In some cases, you are not pulling a Git submodule but you are simply look to update your existing Git submodule in the project.在某些情况下,您不会拉取 Git 子模块,而只是希望更新项目中现有的 Git 子模块。 Like you code on module A but need to use the new feature on module B就像您在模块 A 上编写代码但需要使用模块 B 上的新功能一样

git submodule update --remote --merge

when you clone paren repos, git do not auto clone submodule, you must update and pull submodule当你克隆paren repos时,git不自动克隆子模块,你必须更新并拉取子模块

git submodule update --init
git submodule update --recursive --remote
git pull --recurse-submodules

when submodule is no longer use, you can remove it当子模块不再使用时,您可以将其删除

git submodule deinit <path_to_submodule_folder> -f
git rm <path_to_submodule_folder>
git commit -m "Remove submodule" .
rm -rf .git/modules/<path_to_submodule_folder>

I don't use A too much either, so here are some uses I know.我也不经常使用 A,所以这里有一些我知道的用途。

Hopefully this help you.希望这对你有帮助。

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

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