I have a project that used to contain a submodule, at path mysubmodule
. I installed the latest Git from source (1.8.3-rc2) and ran git submodule deinit mysubmodule
. I then deleted the .gitmodules
file and committed the change. I also deleted the .git
directory from the mysubmodule
folder.
I'd like to commit the files from mysubmodule
into my repo directly now, but git says there are no changes. If I type git add mysubmodule
it does nothing. If I type git add mysubmodule/file.txt
it says fatal: Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'
I've also discovered if you check out a fresh version of the repo, it creates a mysubmodule
directory, despite having no .gitmodules
file. And running git submodule init
gives you a No submodule mapping found in .gitmodules for path 'mysubmodule'
error.
How do I fix this?
In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.
A submodule can be located anywhere in a parent Git repository's working directory and is configured via a . gitmodules file located at the root of the parent repository. This file contains which paths are submodules and what URL should be used when cloning and fetching for that submodule.
Git still think mysubmodule
is a submodule, because it is recorded in the index with a special mode "160000".
See "git submodule update needed only initially?" for more.
To check that, as in in this answer, you can do a:
$ git ls-tree HEAD mysubmodule 160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
That doesn't depend on the presence of the .gitmodule
file, or on the content of mysubmodule
.
You need to remove that entry from the index first:
git rm --cached mysubmodule
Then you can proceed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With