Home > Mobile >  Git submodule suddenly no longer recognized as valid repo, some files in .git/modules/[submodule] mi
Git submodule suddenly no longer recognized as valid repo, some files in .git/modules/[submodule] mi

Time:10-08

I've been having a similar issue as this question, and it likewise seems to have appeared suddenly; however, for me it seems to happen due to a submodule - the error I'm getting on running git status in the main project is

fatal: not a git repository: [submodule]/../.git/modules/[submodule]

When I tried to check whether something had happened to the paths in [submodule]/.git or .git/modules/[submodule]/config as suggested in this answer to a similar question, I found that the latter didn't exist, and more was missing. Specifically, for me the only contents of .git/modules/[submodule] are the refs and objects dirs and packed-refs.

I've tried to add a HEAD as suggested in a comment on the first question but can't quite work out what to put as ref - a simple refs/heads/foo (where heads/foo exists in the refs dir in .git/modules/[submodule], I checked that much) fails with

fatal: bad object HEAD
fatal: 'git status --porcelain=2' failed in submodule

and trying to point it at [submodule]../.git/modules/[submodule]/refs/heads/foo only gives me the original error. Can I get back to a usable submodule, and if so, how? For the submodule, there fortunately is a remote repo with all the changes, ditto for most of the main project (I was in the middle of trying out something I hadn't tracked just yet, so would prefer not having to nuke it...).

CodePudding user response:

Solved it (after this hint from @torek):

I first deleted the submodule by manually carrying out the steps described here (to avoid git potentially choking on the no-longer-a-repo subdirectory): manually deleting the [submodule] sections from .git/config, and removing .git/modules/[submodule] as well as the dir with the submodule. At this point, the main project behaved like a repo again, so I could stage that last change (with git add [submodule]) to get the submodule out of the index. After that, I could re-add the submodule with git submodule add [url/to/submodule].

  • Related