In one of our git repo, there was a submodule added at some point. Now, whenever I checkout a state of the git repo, where the submodule was not yet there it does not properly "remove" the submodule. It seems to be in a state, where the submodule is half there, half not.
I also noticed, that the submodule is no longer preset in .gitmodules but its folders in path/to/submodule and in .git/modules still exist.
I tried at least the following things:
git status => Untracked files: path/to/submodule
git reset --hard => unchanged
git submodule foreach reset --hard => unchanged
git clean -d -f => Skipping repository path/to/submodule
git submodule update --init => unchanged
But until now I did not get it solved. Of course I could manually delete these folders, but I want it to work automatically, when I switch commits, as this is also an issue on our CI (Jenkins).
Any help / hint is highly appreciated!
You need to run git clean with double -f arguments. From the documentation (emphasis mine):
-f --force
If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given. This affects also git submodules where the storage area of the removed submodule under .git/modules/ is not removed until -f is given twice.
So the correct command is: git clean -d -f -f
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