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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:49:55  来源:igfitidea点击:

git: change origin of cloned submodule

gitgithubgit-submodules

提问by Explosion Pills

I created a project submoduleand 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 版本。

  1. If present, change the urlentry in the [submodule "<dirname>"]section of the .gitmodulesfile.
  2. If present, change the urlentry in the [submodule "<dirname>"]section of the .git/configfile.
  3. Change the urlin the configuration of the submodule itself. The location of the configfile 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:
  1. 如果存在,请更改文件部分中的url条目。[submodule "<dirname>"].gitmodules
  2. 如果存在,请更改文件部分中的url条目。[submodule "<dirname>"].git/config
  3. 更改url子模块本身的配置。config文件的位置取决于版本。旧版本<dirname>/.git/config.git/modules/<dirname>/config. 但是,您始终可以使用以下命令:
cd <dirname>
git config remote.origin.url <new_url>