[英]How to change a tracked folder into a git submodule
I'd like to change one folder in my project into a submodule.我想将项目中的一个文件夹更改为子模块。 This is my (sumplified) directory structure:
这是我的(总结)目录结构:
|-app <- the root of git project
|--themes
|--plugins
|--lib
Now, I want to turn app/plugins into a submodule so that I commit changes in this directory into a separate reposiotry.现在,我想将 app/plugins 变成一个子模块,以便我将此目录中的更改提交到一个单独的存储库中。
After setting up a new repo for plugins, I've tired git submodule add <submodule-repository> plugins
, but then I receive a message the reads为插件设置新的 repo 后,我厌倦了
git submodule add <submodule-repository> plugins
,但随后我收到一条消息,读取
app/plugins' already exists in the index
app/plugins' 已经存在于索引中
Sure it exists in the index since it was tracked as part of the main project repository.肯定它存在于索引中,因为它被作为主项目存储库的一部分进行跟踪。
How should I solve it?我该如何解决? Should I perhaps delete the main
.git
folder, add app/plugins
to .gitignore, commit again, and then run git submodule add
?我是否应该删除主
.git
文件夹,将app/plugins
添加到 .gitignore,再次提交,然后运行git submodule add
?
This actually raises another question, should a folder that is a submodule of the project be added to .gitignore
of the project that includes the submodule?这实际上提出了另一个问题,是否应该将作为项目子模块的文件夹添加到包含子模块的项目的
.gitignore
中?
I managed to answer my own question.我设法回答了我自己的问题。 Perhaps I posted too soon.
可能是我发的太早了。 Nevertheless maybe it will help some people in the future:
不过也许它会在未来帮助一些人:
In order to turn a folder tracked in the current project into this project's submodule, I took the following steps:为了将当前项目中跟踪到的文件夹转换为该项目的子模块,我采取了以下步骤:
git rm -rf <folder_that_will_be_a_submodule>
;git rm -rf <folder_that_will_be_a_submodule>
从主项目中删除这个文件夹;rm -rf
;rm -rf
做同样的事情;.git
lives);.git
所在的位置);git submodule add <repository>
;git submodule add <repository>
;.gitignore
(if it has been referenced there)..gitignore
删除对现在是子模块的文件夹的引用(如果它已在那里被引用)。 Hope it will help somebody.希望它会帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.