问题
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
.gitmoduleto removeSource/CrashProbe. - delete your
Source/CrashProbefolder (simple delete, no git command needed, since it is untracked anyway) - check your
.git/modulesfolder to remove anySource/CrashProbetrace 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