[英]Changing the remote repository of git submodule for all commits in git history
如何在不破壞提交歷史記錄的情況下更改 git 子模塊的遠程 url? 目前,如果我檢查舊提交,我的子模塊似乎不再存在舊的遠程 url 女巫。
我的工作流程:
Push.gitmodules 到遠程(提交 C)
使用提交 A、B、C 克隆存儲庫
-> 還想要新的子模塊遠程 URL,但仍然是舊的 url in.gitmodules
看來git submodule update --init
仍在嘗試使用舊的遠程 url
如果還按照建議嘗試使用git submodule update
,但我也得到了錯誤:
The Git repository with name or identifier OLD_REPO_NAME does not exist or you do not have permissions for the operation you are attempting.
讓我們嘗試另一種方法。 而不是替換配置文件中的 URL,而是動態替換 URL:
git config --global url.<NEW-URL>.insteadOf <OLD-URL>
請參閱git help config
url.<base>.insteadOf
。
提交與遠程無關。 一旦您更改了遙控器,該更改對所有新舊提交都有效。
要為您需要的子模塊更改 URL:
.gitmodules
;git submodule sync
將更改復制到.git/config
cd
進入子模塊並運行git remote set-url
以更改子模塊中的 URL。 當您在超級項目中簽出舊提交時,您會得到舊的.gitmodules
但這沒關系git
不使用來自 .gitmodules 的.gitmodules
它使用來自.git/config
的 URL。 git sync
將 URL 從.gitmodules
復制到.git/config
。 因此,在使用舊的.gitmodules
簽出舊提交后,請勿運行git sync
,並且git
將繼續使用來自.git/config
的新 URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.