Forked GIT submodule, and changed source URL. But

2019-05-18 02:21发布

问题:

I have a submodule in my git project, which I have made some changes to, and uploaded to my own git server to fork it. I've changed the source URL in the master git repository to the new submodule's location, and ran git submodule sync so my .git/config file is up to date. Then i pushed everything to Bitbucket, where my data is stored. However, when I clone my main git repository, it is still pulling down the data for the submodule from the old location. Any idea what might be causing this to happen and how to fix it? It's making my forked changes not come up when I clone the repository.

回答1:

Most likely your .gitmodules file is incorrect.

If you open it with your text editor, you will see something like this:

[submodule "externals/submodule"]
    path = externals/submodule
    url = git@github.com:Original/repo.git

Change the url to the updated location, rerun the git submodule sync and you should be good to go.



回答2:

Check the URL setting in .gitmodules and your_submodule/.git/config.



回答3:

Once you have modified the .gitmodules file, a git submodule sync will only modify your .git/config, but won't change anything in .git/modules/yourSubmodule

That means a simple git submodule update yourSubmodule will still use the url stored in .git/modules/yourSubmodule/config, hence the 'old' url.

But if you do:

git submodule update --init yourSubmodule

Then the .git/modules/yourSubmodule is initialized again, with the proper new url, and the submodule is clones from that new url.

For that to work, I prefer deleting completely the submodule from my working tree first.

# restore an empty yourSubmodule directory
rm -Rf yourSubmodule ; git checkout -- yourSubmodule
# update .gitmodules
git submodule sync
git submodule update --init yourSubmodule