1

So I've somehow managed to create a zombie git submodule.

$ cat .gitmodules 
[submodule "Source/CrashProbe"]
    path = Source/CrashProbe
    url = https://github.com/bitstadium/CrashProbe.git

git thinks the submodule is untracked:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    Source/CrashProbe/

Deinit doesn't work:

$ git submodule deinit Source/CrashProbe
error: pathspec 'Source/CrashProbe' did not match any file(s) known to git.

Nor does this:

$ git rm --cached Source/CrashProbe
fatal: pathspec 'Source/CrashProbe' did not match any files

... despite the fact that:

$ ls .git/modules/Source/CrashProbe/
FETCH_HEAD      gitdir          objects
HEAD            hooks           packed-refs
branches        index           refs
config          info            sourcetreeconfig
description     logs

Nor does this:

$ git config -f .git/config --remove-section Source/CrashProbe
fatal: No such section!

... despite the fact that:

$ cat .git/config
...
[submodule "Source/CrashProbe"]
    url = https://github.com/bitstadium/CrashProbe.git

That about exhausts all SO answers I've seen so far, so my question is: How do I get out of this mess and have a proper submodule?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Karl
  • 14,434
  • 9
  • 44
  • 61

2 Answers2

2

Try to remove the submodule file and declaration manually.

  • Edit you .gitmodule to remove Source/CrashProbe.
  • delete your Source/CrashProbe folder (simple delete, no git command needed, since it is untracked anyway)
  • check your .git/modules folder to remove any Source/CrashProbe trace in it.

Once that is done, add and commit (to get back to a clean state).

And then try your git submodule add command again

git submodule add -- https://github.com/bitstadium/CrashProbe.git Source/CrashProbe
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Aaaand it turns out I'd forgotten to do a git commit.

How I hate git and its cryptic interface...

Edit: I'd created the submodule, but didn't include the submodule dir in my commit. This left the repo in an inconsistent state (.gitmodules committed, submodule not). Git's error reporting is, shall we say, lacking.

Karl
  • 14,434
  • 9
  • 44
  • 61
  • No, what I meant was that I created the submodule, but didn't commit Source/CrashProbe. That caused git to add all the relevant entries internally, but none of it reflected reality, and it left the repo in an inconsistent state (.gitmodules committed, but the submodule not). git add and git commit fixed it. The issue is that git is incredibly obtuse and unhelpful, on top of being user unfriendly. – Karl Feb 01 '17 at 21:18
  • OK. +1 then. You need to add the gitlink indeed. See http://stackoverflow.com/a/9857021/6309 for an illustration of what a gitlink is (also: http://stackoverflow.com/a/16581096/6309 and http://stackoverflow.com/a/19354410/6309) – VonC Feb 01 '17 at 21:22