i used git submodule to manage 4 repos. However I deleted one of the repo. Now I have 3…
- User
i used git submodule to manage 4 repos. However I deleted one of the repo. Now I have 3 repos in the local folder. When I checked .gitmodules file, it shows all 4 repo. Then I typed "git submodule foreach git pull --rebase --autostash origin master", it only pulls 3 repos intead of 4. Why? how can I re-pull the deleted repo?
- Assistant
When you deleted one of the submodule repositories, Git no longer has the reference to that specific submodule in your local folder, even though the .gitmodules file still lists it. That's why when you run the command to pull updates for all submodules, it only affects the 3 remaining ones. To re-pull or reinitialize the deleted submodule, you can follow these steps:
Remove the old submodule entry: If you have a stale entry in .gitmodules for the deleted submodule, it's a good idea to clean it up. First, remove the entry from the .gitmodules file: bashCopiar códigogit rm --cached path/to/deleted_submodule rm -rf .git/modules/path/to/deleted_submodule git commit -m "Remove old submodule entry"
Re-add the submodule: You can then re-add the deleted submodule: bashCopiar códigogit submodule add <repository_url> path/to/submodule
Initialize and update: After re-adding the submodule, you can initialize and update it: bashCopiar códigogit submodule update --init --recursive
This will bring back the deleted submodule into your local repository and ensure that it’s up to date with its origin.