Reputation: 33755
I have a submodule in my repo, and I think I inadvertently deleted the .gitmodules
file.
I don't want to do git submodule add <git@git:...>
because that will pull the original repo for the submodule into the folder and erase the changes I made to the submodule. So all I want to do is just re-create the .gitmodules
file.
How do I re-create it?
Upvotes: 0
Views: 3081
Reputation: 136977
Was the file committed to the repository? If so, you can probably do something like git checkout -- .gitmodules
from the root of the repository.
If the .gitmodules
file was not committed to the repository, you will probably have to rebuild it by hand. Luckily, most of the information that you need can be found in .git/config
:
...
[submodule "vendor/foo"]
url = https://somesite.tld/user/repository.git
...
For each of your submodules, copy this section from .git/config
into .gitmodules
. Then add a new line path
under each section pointing to the location of the module within your repository:
...
[submodule "vendor/foo"]
path = vendor/foo
url = https://somesite.tld/user/repository.git
...
That should get you pretty close to where you were before deleting your .gitmodules
file. You can verify that you've got it right with git submodule status
. If your paths are set incorrectly, you will get something like
No submodule mapping found in .gitmodules for path 'vendor/foo'
If your .gitmodules
is set up correctly, you should see something like
0123456789abcdef01234567890abcdef0123456 vendor/foo (heads/master)
Now that you've got everything sorted out, commit that .gitmodules
file! It should be part of your repository.
Upvotes: 1