Git-如何更改子模块的URL/路径 [英] Git - How to change url/path of a submodule

查看:6
本文介绍了Git-如何更改子模块的URL/路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的.gitmodules

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://company@bitbucket.org/some_user/ethanyehuda_cronjobmanager.git

我需要将url更改为https://github.com/Ethan3600/magento2-CronjobManager.git

所以我就改了:

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://github.com/Ethan3600/magento2-CronjobManager.git

然后我将文件添加到临时区域并提交:

git add .gitmodules
git commit -m "change url of submodule xy"

然后执行git submodule update --init。但如果我转到app/code/EthanYehuda/CronjobManager并显示遥控器,我仍然会看到https://company@bitbucket.org/some_user/ethanyehuda_cronjobmanager.git

推荐答案

对我来说,我找到的解决方案不起作用,因为我的存储库的GIT历史记录与新存储库的历史记录完全不同。

让我解释一下。我收到了一个Zip文件形式的项目。我初始化了一个新的回购,提交了文件并将其推送到我的BitBucket。

然后我发现,这是一个公共GitHub项目。因此,我想将URL更改为GitHub存储库。但它们拥有完全不同的GIT历史(我的repo只有一个初始提交,而GitHub repo包含所有提交。)

因此,仅更改URL不会起作用。

所以我必须删除子模块,然后重新创建它。

提示<name_of_submodule>=app/code/Ethan Yehuda/CronjobManager(在我的 案例)

删除:

git submodule deinit <name_of_submodule>
git rm -f <name_of_submodule>
rm -rf .git/modules/<name_of_submodule>
git commit -m "Deleted submodule xy"

重新添加:

git submodule add --force https://github.com/example/foo-bar.git <name_of_submodule>
git commit -m "Add submodul xy"

获取子模块app/code/Ethan Yehuda/CronjobManager错误: 服务器拒绝对未指定对象的请求 9b677ef0e750acb92920306bd97a3ee2734c61

↑如果在克隆上拉出项目后出现这样的错误,例如Stage,则您必须在git pull之后syncupdate --init

git submodule sync
git submodule update --init

这篇关于Git-如何更改子模块的URL/路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆