d4Rk d4Rk - 1 year ago 69
Git Question

checkout commit with different submodule setup does not work properly

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

but its folders in
and in
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!

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download