Git - 如何更改子模块的 url/path
Git - How to change url/path of a submodule
这是我的 .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
您需要在更新 url 后删除并重新同步您的子模块。
请参考此回答。
有关详细信息,请参阅 this 答案。
这些命令将在命令提示符下完成工作,而不会更改本地存储库中的任何文件
git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git
git config --file=.gitmodules submodule.Submod.branch Development
git submodule sync
git submodule update --init --recursive --remote
对我来说,我找到的解决方案没有用,因为我的存储库的 git 历史与新存储库的历史完全不同。
让我解释一下。我收到了一个 Zip 文件形式的项目。我初始化了一个新的 repo 并提交了文件并将其推送到我的 bitbucket。
然后我发现,这是一个 public github 项目。所以我想将 URL 更改为 github 存储库。但是他们有完全不同的 git 历史(我的仓库只有一个初始提交,而 github 仓库包含所有提交。)
因此仅更改 URL 是行不通的。
所以我不得不删除子模块并重新创建它。
Hint: <name_of_submodule>
= app/code/EthanYehuda/CronjobManager (in my
case)
删除:
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"
Fetching submodule app/code/EthanYehuda/CronjobManager error: The
server refused requests to not specified object
9b677ef0e750acb9292030306bd97a3ee2734c61
↑ 如果在将项目拉到克隆上后出现这样的错误,例如分期,那么你必须在 git pull
:
之后 sync
和 update --init
git submodule sync
git submodule update --init
.gitmodules
保留建议的默认值,您的更改将在设置后续克隆时生效。
一旦有人完成了克隆,生成的存储库就只是一个存储库。您可以进入现有子模块的目录并以通常的方式更改其源远程 url,但是 git submodule
命令具有 a handy shortcut、
git submodule sync
为您填空。
sync [--recursive] [--] [<path>…]
Synchronizes submodules' remote URL configuration setting to the value specified in .gitmodules
. It will only affect those submodules which already have a URL entry in .git/config
(that is the case when they are initialized or freshly added). This is useful when submodule URLs change upstream and you need to update your local repositories accordingly.
git submodule sync
synchronizes all submodules while git submodule sync -- A
synchronizes submodule "A" only.
If --recursive
is specified, this command will recurse into the registered submodules, and sync any nested submodules within.
自 git v2.25.0(changelog), git submodule
learn the new set-url 命令。
要使用它,只需执行 git submodule set-url -- <path> <url>
对你来说是:
git submodule set-url -- app/code/EthanYehuda/CronjobManager https://github.com/Ethan3600/magento2-CronjobManager.git
注意:无论您在 git 中的哪个位置,路径都应相对于顶级目录。
这是我的 .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
您需要在更新 url 后删除并重新同步您的子模块。
请参考此回答。
有关详细信息,请参阅 this 答案。
这些命令将在命令提示符下完成工作,而不会更改本地存储库中的任何文件
git config --file=.gitmodules submodule.Submod.url https://github.com/username/ABC.git
git config --file=.gitmodules submodule.Submod.branch Development
git submodule sync
git submodule update --init --recursive --remote
对我来说,我找到的解决方案没有用,因为我的存储库的 git 历史与新存储库的历史完全不同。
让我解释一下。我收到了一个 Zip 文件形式的项目。我初始化了一个新的 repo 并提交了文件并将其推送到我的 bitbucket。
然后我发现,这是一个 public github 项目。所以我想将 URL 更改为 github 存储库。但是他们有完全不同的 git 历史(我的仓库只有一个初始提交,而 github 仓库包含所有提交。)
因此仅更改 URL 是行不通的。
所以我不得不删除子模块并重新创建它。
Hint:
<name_of_submodule>
= app/code/EthanYehuda/CronjobManager (in my case)
删除:
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"
Fetching submodule app/code/EthanYehuda/CronjobManager error: The server refused requests to not specified object 9b677ef0e750acb9292030306bd97a3ee2734c61
↑ 如果在将项目拉到克隆上后出现这样的错误,例如分期,那么你必须在 git pull
:
sync
和 update --init
git submodule sync
git submodule update --init
.gitmodules
保留建议的默认值,您的更改将在设置后续克隆时生效。
一旦有人完成了克隆,生成的存储库就只是一个存储库。您可以进入现有子模块的目录并以通常的方式更改其源远程 url,但是 git submodule
命令具有 a handy shortcut、
git submodule sync
为您填空。
sync [--recursive] [--] [<path>…]
Synchronizes submodules' remote URL configuration setting to the value specified in
.gitmodules
. It will only affect those submodules which already have a URL entry in.git/config
(that is the case when they are initialized or freshly added). This is useful when submodule URLs change upstream and you need to update your local repositories accordingly.
git submodule sync
synchronizes all submodules whilegit submodule sync -- A
synchronizes submodule "A" only.If
--recursive
is specified, this command will recurse into the registered submodules, and sync any nested submodules within.
自 git v2.25.0(changelog), git submodule
learn the new set-url 命令。
要使用它,只需执行 git submodule set-url -- <path> <url>
对你来说是:
git submodule set-url -- app/code/EthanYehuda/CronjobManager https://github.com/Ethan3600/magento2-CronjobManager.git
注意:无论您在 git 中的哪个位置,路径都应相对于顶级目录。