嵌套git仓库没有遥控器(又名git submodule没有遥控器) [英] Nested git repositories without remotes (a.k.a. git submodule without remotes)

查看:155
本文介绍了嵌套git仓库没有遥控器(又名git submodule没有遥控器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我有兴趣将其中的部分作为开​​源代码分发。我已经在main / one,main / two,main / three中建立了一个maingit仓库(例如,在一个目录main中)和sub-repository。我认为通过进入主并做

  git添加一个
git添加两个
git添加三个

(注意缺少尾部斜线),我会设置子模块,不过,正如 track-untracked-content / 4162672#4162672> Git - 如何跟踪未跟踪的内容?,这只会创建gitlinks而不是真正的子模块。



那个答案没有帮助,因为它假定main / one,main / two和main / three在 else 的某处存在master存储库。我希望这些sub-repo是主存储库。我正在考虑假子模块(按照 Git假子模块),但这对于克隆来说并不是特别理想的情况。



其他任何建议?

一个,两个 ,以及三个都需要可供需要克隆它们的人访问 - 通常情况下,随机开发存储库不是这样。



如果你确实设置了它,你将需要非常小心,不要删除你的存储库(或者使其无法访问),因为它不仅仅是你的:它将是 .gitmodules )中指定的中心/上游存储库。






如果你所有的协作者都是loc al(并且可以从存储库读取),您可以通过将其本地路径作为URL来将现有子存储库添加为子模块:

  git rm --cached one two three 
git submodule add`pwd` / one
git submodule add`pwd` / two
git submodule add`pwd` / three

如果不是所有的协作者都会在同一台机器上工作,那么这可能无法正常工作(因为它会存储 .gitmodules 中的本地路径;非本地协作者必须在 git子模块init 之后调整URL。)



如果您的一个两个三个是远程Git可访问的,那么您可以

  git rm --cached one two three 
git submodule add server:/ path / to / your / main / one
git子模块添加服务器:/ path / to / your / main / two
git子模块添加服务器:/ path / to / your / main / three

在这两种情况下,由于您已经有一个子存储库, git submodule add 将使用它,而不是试图从指定的路径/ URL克隆。


I have a project of which I am interested in breaking out portions as open-source. I've set up a "main" git repository (say, in a directory "main") and sub-repositories in "main/one", "main/two", "main/three". I thought that by going into "main" and doing

git add one
git add two
git add three

(note the lack of trailing slashes), I'd set up submodules with the sub-repositories and be good to go.

However, as noted in Git - how to track untracked content?, this only creates gitlinks and not real submodules.

Unfortunately, that answer doesn't help, as it assumes that there is a "master" repository somewhere else for "main/one", "main/two", and "main/three". I'd like these sub-repo's to be the master repositories. I'm considering fake submodules (as per Git fake submodules), but that's not a particularly ideal situation for cloning.

Any other suggestions out there?

解决方案

You can do what you want, but your one, two, and three would need to be accessible to whoever will need to clone them—this is not usually the case for "random" development repositories.

If you do set this up, you will need to be very careful not to delete "your" repository (or make it otherwise inaccessible) since it is not just "yours": it will be origin in your collaborator’s clones and it will serve as the "central"/"upstream" repository (as specified in .gitmodules).


If all your collaborators are local (and can read from the repositories), you can add your existing sub-repositories as submodules by giving their local paths as URLs:

git rm --cached one two three
git submodule add `pwd`/one
git submodule add `pwd`/two
git submodule add `pwd`/three

If not all your collaborators will be working on the same machine, then that will probably not work correctly (since it will store a local path in .gitmodules; non-local collaborators would have to adjust the URLs after git submodule init).

If your one, two, and three are remotely Git-accessible, then you can specify their effecive URLs instead:

git rm --cached one two three
git submodule add server:/path/to/your/main/one
git submodule add server:/path/to/your/main/two
git submodule add server:/path/to/your/main/three

In both cases, since you already have a sub-repository in place, git submodule add will use that instead of trying to clone from the specified path/URL.

这篇关于嵌套git仓库没有遥控器(又名git submodule没有遥控器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆