1 个目录中的 Git 子模块
我正在为一个开源软件开发几个扩展。每个扩展都有通过我正在编写的软件的文件树分布的文件。最初,我为其中一个扩展创建了一个 Git 项目,效果很好。但现在,我需要为其他扩展创建 Git 存储库,但不知道如何执行此操作。如果我只是尝试将项目克隆到我的根工作区,这将覆盖我的第一个 Git 存储库。
根据研究,我认为这可以使用子模块来完成,但是,对子模块的所有引用似乎都将每个模块放在不同的目录中。
我的问题是,是否可以使用子模块将多个 Git 项目全部存放在 1 个目录中?
I'm working on several extensions for an open source piece of software. Each of the extensions have files distributed through the file tree of the software that I am writing for. Initially, I created a Git project for one of those extensions, which worked great. Now though, I need to create Git repo's for the other extensions but cannot figure out how to do this. If I simply try to clone a project to my root workspace, this will overwrite my first Git repo.
Based on research, I think this can be done using sub-modules, however, all references to submodules seem to have each module in a different directory.
My question, is it possible to have several Git projects all housed in 1 directory using sub-modules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不。子模块不应该用于覆盖存储库。
执行此操作的典型方法是为各个扩展创建不同的分支,然后将每个分支合并到表示所有扩展聚合的主分支中。
No. Submodules aren't meant to be used to overlay repos.
The typical way to do this would be to create different branches for the individual extensions and then merge each branch into a master branch that represented the aggregation of all the extensions.
我想出的方法如下:
将项目克隆到根目录中。一旦工作正常,将 .git 文件重命名为 .git-%s,其中 %s 代表项目名称的 2 个字符。然后我将另一个存储库克隆到根目录中并执行相同的操作。对所有项目执行此操作后,我的根目录中有以下 4 个 .git 文件:
root
- .gitwp
- .gitbp
- .gitas
- .gitwps
我现在可以同时处理所有项目。如果我想将更改提交到特定的存储库,我会执行以下操作:
mv .gitwp .git
git commit -m "提交消息"
mv .git .gitwp
我希望这对某人有帮助!
The way I figured how to do this is as follows:
Clone a project into the root. Once it's working, rename the .git file to .git-%s, where %s represents 2 characters representing the project name. I then cloned another repo into the root and did the same. After doing this for all projects, I had the following 4 .git files in my root:
root
- .gitwp
- .gitbp
- .gitas
- .gitwps
I can now work on all projects at once. If I want to commit changes to a specific repo, I do the following:
mv .gitwp .git
git commit -m "Commit Message"
mv .git .gitwp
I hope this helps someone!