git 子模块未出现在 repo 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31117120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Submodule not showing up in repo
提问by eignhpants
I am building some custom rpm packages, and am trying to include the source of another project as a submodule to build from. During my first run I added the package and when I looked at the Github page I could see the icon showing the linked submodule, but it was in the wrong place.
我正在构建一些自定义的 rpm 包,并试图将另一个项目的源代码包含为要构建的子模块。在我第一次运行时,我添加了这个包,当我查看 Github 页面时,我可以看到显示链接子模块的图标,但它位于错误的位置。
I did some changes to place the submodule where I need it (in a /SOURCES
folder) but when I commit or try to do anything to update the repo I am not seeing anything which indicates the submodule is loading in the correct place.
I also don't see any changes when using submodule update
or any other related command.
我做了一些更改以将子模块放置在我需要的位置(在/SOURCES
文件夹中),但是当我提交或尝试执行任何操作来更新存储库时,我没有看到任何表明子模块加载到正确位置的内容。
在使用submodule update
或任何其他相关命令时,我也没有看到任何变化。
Should I just erase the .gitmodules
file and start over? I am worried that will have unforeseen consequences. Is there any command to tell git to check the .gitmodules
file and take action accordingly?
我应该删除.gitmodules
文件并重新开始吗?我担心这会产生不可预见的后果。是否有任何命令可以告诉 git 检查.gitmodules
文件并采取相应措施?
Thanks for any help.
谢谢你的帮助。
回答by eignhpants
I found a solution to this for anyone else who may stumble into this thread. After messing around with updating I ended up adding the submodule again with git submodule add --force <url> <path>
. The --force
option was necessary because git was seeing another module with the same name. Somehow this link was broken and not updating. After this step running git submodule update
, the directory was populated and a link appeared in the github page signifying the change.
我为其他可能偶然发现此线程的人找到了解决方案。在搞砸了更新之后,我最终再次使用git submodule add --force <url> <path>
. 这个--force
选项是必要的,因为 git 看到了另一个同名的模块。不知何故,此链接已损坏且未更新。在这一步运行后git submodule update
,目录被填充,github 页面中出现一个链接,表示更改。
I found this information in the following link:
我在以下链接中找到了此信息:
回答by CodeWizard
Before using submodules you have to init then and only aftr that you can update them.
在使用子模块之前,您必须先初始化,然后才能更新它们。
git submodule add <url> <name>
Then you .git/config
should contain the following entry:
那么你.git/config
应该包含以下条目:
[submodule "name"]
path = extension
url = <url>
Now you have submodules in a project, at this point you have to init and "install" it under the main repository (it should clone the submodule content to the defined path).
现在您在项目中有子模块,此时您必须在主存储库下初始化并“安装”它(它应该将子模块内容克隆到定义的路径)。
git submodule init
git submodule update
Now you all set to go.
现在你们都准备好了。
When I commit or try to do anything to update the repo I am not seeing anything which indicates the submodule is loading in the correct place.
当我提交或尝试做任何事情来更新 repo 时,我没有看到任何表明子模块加载到正确位置的内容。
submodule
is a standalone repository so any changes made inside the submodule folder are not visible outside of this folder and vice versa.
submodule
是一个独立的存储库,因此在子模块文件夹内所做的任何更改在该文件夹之外都是不可见的,反之亦然。
Any changes made under the submodule have to commited seperatly inside the submodule folder.
在子模块下所做的任何更改都必须在子模块文件夹中单独提交。