簡體   English   中英

為 git 歷史記錄中的所有提交更改 git 子模塊的遠程存儲庫

[英]Changing the remote repository of git submodule for all commits in git history

如何在不破壞提交歷史記錄的情況下更改 git 子模塊的遠程 url? 目前,如果我檢查舊提交,我的子模塊似乎不再存在舊的遠程 url 女巫。

我的工作流程:

  1. 使用提交 A,B 克隆 repo
  2. git子模塊更新--init
  3. 更改子模塊 url
  4. Push.gitmodules 到遠程(提交 C)

  5. 使用提交 A、B、C 克隆存儲庫

  6. 切換到提交 A
  7. git 子模塊更新--init -> FAILES

-> 還想要新的子模塊遠程 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 文件中的.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM