在另一个 git 仓库中维护 git 仓库
我想要的是:
REPO-A
/.git
/otherFiles
/REPO-B
/.git
/moreFiles
我希望能够将 REPO-A 的全部内容推送到 REMOTE-A,仅将 REPO-B 内容推送到 REMOTE-B。
可能的?
Here's what I'd like:
REPO-A
/.git
/otherFiles
/REPO-B
/.git
/moreFiles
I want to be able to push all of REPO-A's contents to REMOTE-A and only REPO-B to REMOTE-B.
Possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
听起来您想使用 Git 子模块。
It sounds like you want to use Git submodules.
我一直使用符号链接来维护两个独立且不同的存储库。
I have always used symlinks to maintain two separate and distinct repos.
是的,您可以使用您绘制的文件层次结构完全按照您的要求进行操作。 Repo-B 将是独立的,并且不了解 Repo-A。 Repo-A 将跟踪它自己的文件和 Repo-B 文件中的所有更改。
但是,我不建议这样做。每次您更改文件并在 Repo-B 中提交时,您都必须在 Repo-A 中提交。 Repo-B 中的分支会与 Repo-A 混淆,而 Repo-A 中的分支会很不稳定(删除文件夹等时出现问题)。子模块绝对是最佳选择。
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.
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.
您可以在父
A
存储库中使用.gitignore
文件(忽略B
),但首先确保B
当前未跟踪 code> 存储库:在添加第二个B
存储库之前提交父级.gitignore
。You can use a
.gitignore
file in the parentA
repository (ignoringB
), but firstly making sure that theB
repository is not currently being tracked: commit the parent.gitignore
before adding the secondB
repository.对于在问题首次发布几年后来到这里的人们:
git subtree
就是您正在寻找的:如果其他人克隆 REPO-A,他们也将获得 REPO -B 的内容(与 git submodule 不同),但它们没有远程规范。对他们来说,REPO-A 就好像一个单一的存储库。
您可以在以下位置阅读有关 git subtree 的更多信息:https:// www.atlassian.com/git/tutorials/git-subtree
For people coming here a few years after the question was first posted:
git subtree
is what you're looking for:If someone else clones REPO-A they will also get REPO-B's contents (unlike
git submodule
) but they won't have the remote spec. To them it'll be as if REPO-A is a single repository.You can read more about
git subtree
at: https://www.atlassian.com/git/tutorials/git-subtree您可以通过使用“git-subrepo”来实现您想要的(REPO-A 存储库包含所有文件,包括文件夹 REPO-B 中的文件,而不仅仅是参考):
https://github.com/ingydotnet/git-subrepo
如果您的某些贡献者没有安装 subrepo 命令,它仍然有效;他们将看到完整的文件夹结构,但无法提交对子存储库的更改。
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":
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.
就我而言,我不想将存储库 A 与存储库 B 合并,因此存储库内的存储库工作得很好。只需仔细更新两个
repos
的.gitignore
即可。并确保在使用 git 命令时位于各自的目录中。
一些简短的说明:
repos
将独立运行,因此无法合并。除非添加到其
.gitignore
除非添加到其子文件夹和文件中,否则会更改
.gitignore
。.gitignore
文件将起作用彼此独立。
因此,例如,如果您想忽略子存储库中的文件但想要
要将其推送到父存储库中,只需将文件添加到子存储库的
.gitignore
中。repos
,则上述指南将被视为无效。因此,在使用回购策略中的回购时,应适当研究整体情况。In my case, I didn't want to merge repo A with repo B so the repo inside the repo works perfectly fine. Just carefully update the
.gitignore
for bothrepos
.And make sure to stay inside the respective dir while using git commands.
Some quick notes:
repos
will act independently and thus can not be merged.unless added to its
.gitignore
changes inside its subfolders and files unless added to its
.gitignore
..gitignore
files will actindependently of each other.
So, for example, if you want to ignore a file in the child repo but want
to push it in the parent repo, just add the file in the child repo's
.gitignore
repos
need to be merged, the above guide will be considered invalid. So, the overall case should be studied properly to use the repo inside the repo strategy.有很多选择,最好的选择取决于您的目的:
如果希望将父级保留为不同应用程序的容器,并且其中一些最终可能成为存储库 ,只需使用裸 Git 将它们视为不同的存储库(没有子模块就没有子存储库)。无需了解更多 git 功能。
如果您希望将父级保留为不同存储库的“项目”,并在管理不同协作者的访问时感到安全,那么对不同存储库文件夹使用符号链接的解决方案是一个不错的选择。再次强调,无需学习更多 git 功能。
说明:
如果其中一个应用程序成为存储库,只需在那里进行 git init,添加远程存储库并忘记 git 教程,然后将时间花在应用程序上。它只是工作,并且在父存储库中,提交对于其余应用程序来说仍然是原子的,有时会有额外的提交,是的,但是您不需要需要为每个提交提交parentA回购协议B。您可以对两个存储库应用不同的权限(尽管父级可以拥有 repoB 代码,除非您使用 .gitignore 忽略 repoB)。
Lots of choices, the best one depends on your purpose:
if want to keep the parent as a container of different apps, and some of them could eventually become repos, just use bare Git to treat them as different repos (no submodules no subrepos). No need to learn more git features.
if you want to keep the parent as a "project" of different repos and feeling safe on managing access for different collaborators, the solution of using symbolic links for different repo folders is a good option. Again, no need to learn more git features.
Explanation:
If one of the app becomes a repo, just
git init
there, add the remote repo and forget git tutorials and spend that time for the apps. It just work, and in the parent repo the commits can still be atomic for the rest of apps, and sometimes there will be extra commits,yes, but you do not need to commit parentA for each commit of repoB. You can apply different permisions on both repos (although parent can have repoB code unless you use .gitignore to ignore the repoB) .还有一种方法可以处理这个问题。您可以将存储库(即子模块)放置为每个单独的独立存储库。并且可以创建到主存储库内的子模块存储库的软链接。
一旦列出了 main-repo 中的文件,就会列出子模块 SoftLinks
There is one more way this could be handled. You can place the repos(that are submodules) as each separate independent repository. And can create softlinks to the submodule repos inside the master repo.
Once files inside main-repo are listed, the submodules SoftLinks are listed
我发现最简单的是编辑 REPO-A 的 .git/info/exclude
它应该看起来像这样。刚刚添加了下面的最后一行。
Simplest I found is to edit REPO-A's .git/info/exclude
it should look something like this. Just added the last line below.