git:更改克隆子模块的来源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10317676/
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
git: change origin of cloned submodule
提问by Explosion Pills
I created a project submodule
and put it up on Github.
我创建了一个项目submodule
并将其放在 Github 上。
I created another project, supermodule
, and then did this:
我创建了另一个项目,supermodule
然后这样做:
cd supermodule
git init
mkdir lib
git clone git://github.com/tandu/submodule lib/submodule
git submodule add ./lib/submodule lib/submodule
This worked fine, but on the website, it can't find the link to the submodule when viewing the files (in fact it just says "Loading Commit data" forever). The submodule folder itself has the correct origin
.
这工作正常,但在网站上,查看文件时找不到子模块的链接(实际上它只是永远说“加载提交数据”)。子模块文件夹本身具有正确的origin
.
Apparently, what I should have done was
显然,我应该做的是
...
mkdir lib
git submodule add git://github.com/tandu/submodule lib
...but it's too late for that now. How can I have the submodule in this project correctly point to origin
?
……但现在为时已晚。我怎样才能让这个项目中的子模块正确指向origin
?
回答by Michael Wild
This apparently is very much dependent on the version of git you are using.
这显然在很大程度上取决于您使用的 git 版本。
- If present, change the
url
entry in the[submodule "<dirname>"]
section of the.gitmodules
file. - If present, change the
url
entry in the[submodule "<dirname>"]
section of the.git/config
file. - Change the
url
in the configuration of the submodule itself. The location of theconfig
file is version dependent. Older versions had it in<dirname>/.git/config
, newer ones in.git/modules/<dirname>/config
. However, you can always use below command:
- 如果存在,请更改文件部分中的
url
条目。[submodule "<dirname>"]
.gitmodules
- 如果存在,请更改文件部分中的
url
条目。[submodule "<dirname>"]
.git/config
- 更改
url
子模块本身的配置。config
文件的位置取决于版本。旧版本<dirname>/.git/config
在.git/modules/<dirname>/config
. 但是,您始终可以使用以下命令:
cd <dirname>
git config remote.origin.url <new_url>