How to change the remote repository for a git submodule?

后端 未结 7 1215
醉梦人生
醉梦人生 2020-11-22 10:45

I\'ve created a git repository with a submodule in it. I\'m able to tell the submodule itself to change its remote repository path, but I\'m not sure how to tell the parent

7条回答
  •  孤街浪徒
    2020-11-22 11:22

    What worked for me (on Windows, using git version 1.8.3.msysgit.0):

    • Update .gitmodules with the URL to the new repository
    • Remove the corresponding line from the ".git/config" file
    • Delete the corresponding directory in the ".git/modules/external" directory (".git/modules" for recent git versions)
    • Delete the checked out submodule directory itself (unsure if this is necessary)
    • Run git submodule init and git submodule update
    • Make sure the checked out submodule is at the correct commit, and commit that, since it's likely that the hash will be different

    After doing all that, everything is in the state I would expect. I imagine other users of the repository will have similar pain when they come to update though - it would be wise to explain these steps in your commit message!

提交回复
热议问题