在另一个 git repo 中维护 git repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4659549/
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 09:49:54  来源:igfitidea点击:

Maintain git repo inside another git repo

gitversion-controlgithub

提问by adamyonk

Here's what I'd like:

这是我想要的:

REPO-A
  /.git
  /otherFiles
  /REPO-B
    /.git
    /moreFiles

I want to be able to push allof REPO-A's contents to REMOTE-A and onlyREPO-B to REMOTE-B.

我希望能够将所有REPO-A 的内容推送到 REMOTE-A,而仅将REPO-B推送到 REMOTE-B。

Possible?

可能的?

采纳答案by mipadi

It sounds like you want to use Git submodules.

听起来您想使用 Git submodules

Git addresses this issue using submodules. Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate.

Git 使用子模块解决了这个问题。子模块允许您将 Git 存储库保留为另一个 Git 存储库的子目录。这使您可以将另一个存储库克隆到您的项目中并保持您的提交分开。

回答by JohnO

I have always used symlinks to maintain two separate and distinct repos.

我一直使用符号链接来维护两个独立且不同的存储库。

回答by kubi

Yes, you can do exactly what you're asking with the file hierarchy you drew. Repo-B will be independant and have no knowledge of Repo-A. Repo-A will track all changes in it's own files and Repo-B's files.

是的,您可以使用您绘制的文件层次结构完全满足您的要求。Repo-B 将是独立的并且不了解 Repo-A。Repo-A 将跟踪它自己的文件和 Repo-B 文件中的所有更改。

However, I would not recommend doing this. Every time you change files and commit in Repo-B you'll have to commit in Repo-A. Branching in Repo-B will mess with Repo-A and branching in Repo-A will be wonky (trouble removing folders, etc.). Submodules are definitely the way to go.

但是,我不建议这样做。每次更改文件并在 Repo-B 中提交时,您都必须在 Repo-A 中提交。在 Repo-B 中分支会与 Repo-A 混淆,在 Repo-A 中分支会很不稳定(无法删除文件夹等)。子模块绝对是要走的路。

回答by Glue

You can achieve what you want (that REPO-A repo contains all the files, including those in folder REPO-B instead of only a reference) by using "git-subrepo":

您可以通过使用“git-subrepo”来实现您想要的(该 REPO-A 存储库包含所有文件,包括文件夹 REPO-B 中的文件,而不仅仅是引用):

https://github.com/ingydotnet/git-subrepo

https://github.com/ingydotnet/git-subrepo

It still works if some of your contributors don't have the subrepo command installed; they will see the complete folder structure but won't be able to commit changes to the subrepos.

如果你的一些贡献者没有安装 subrepo 命令,它仍然有效;他们将看到完整的文件夹结构,但无法提交对子存储库的更改。