Git: Zombie submodule

我们两清 提交于 2020-02-02 13:56:04

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/41947585/git-zombie-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!