0

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...).

KeyboardCat
  • 442
  • 3
  • 12
  • 1
    You can remove the submodule completely and re-clone it (just move the existing one out of the way, saving whatever you have just in case you want it back later). It's probably a good idea to figure out what clobbered it though, to avoid having it happen again. – torek Oct 06 '21 at 23:05
  • @torek - I would suspect a fumbled accidental `rm` back when I set up the submodule (I messed up the order of adding it and running `git-filter-repo` on the main project several times...) that I thought I'd stopped in time, except that it evidently *was* working for a while... – KeyboardCat Oct 07 '21 at 06:18

1 Answers1

0

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].

KeyboardCat
  • 442
  • 3
  • 12