英文:
How can I get a common local clone of a git repo and share it as a submodule of multiple other local git repo clones?
问题
我有多个项目(存储库),它们都使用相同的子模块。每个项目的子模块都显示在vs-code源代码控制的“概览”中。
我只想在这个概览中看到一个子模块,这样我就可以对一个子模块进行更改,然后应用到每个项目。
我尝试隐藏我不想看到的存储库,但问题是,当我更改一个子模块时,我必须再次为每个单独的项目拉取子模块,这并不理想。
英文:
I have multiple projects (repositories) which use the same submodules. Every projects submodule is displayed in the vs-code source control "overview".
Screenshot of source control overview
I want just one submodule in this overview so that I can make changes to the one sumodule, which apply to every project.
I tried to hide the respositories I don't want to see but then the problem is that when I change one submodule I have to pull for every single project again the submodule, which is not ideal.
答案1
得分: 1
如果每个项目都与一个子模块具有相同的上游,它们仍然是独立的子模块,对一个子模块所做的修改不会自动传递到其他子模块,所以它们确实是不同的,我认为神秘地只在VS Code SCM Outline中显示其中一个将带来更多害处而不是好处。
我认为您可以通过使用指向共享本地检出的子模块来解决您的问题和设置。尝试在文件系统的某个位置克隆该共享存储库,然后添加指向它或其 .git 目录的子模块。例如,如果您当前的工作目录是存储库 A 的目录,并且您将共享存储库克隆为 A 的兄弟目录,然后执行 git submodule add ../<common-repo-directory-name>/.git
。如果您遇到类似“fatal: transport 'file' not allowed”的错误,请尝试执行 -c protocol.file.allow=always
。
相关链接:https://stackoverflow.com/q/6100966/11107541。
英文:
If each project has the same upstream as a submodule, they're still separate submodules, and a modification you make to one submodule does not automatically carry over to others, so they really are different, and I think it would be more harm than good to mysteriously only show one of them in the VS Code SCM Outline.
What I think you can do with your problem and setup is to just use submodules that point to a common local checkout. Try cloning that common repo somewhere onto your filesystem, and then adding submodules that point to it or its .git directory. Ex. If your current working directory is the directory of repo A, and you clone the common repo as a sibling directory of A, then do git submodule add ../<common-repo-directory-name>/.git
. If you get an error like "fatal: transport 'file' not allowed", then try doing -c protocol.file.allow=always
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论