1

I had a directory tree which contained a git repository (which I did not think of at that time). Then in a father two dirs up I did a git init and tried to add everything in that tree. It did not add the files in the subdir which already had a .git directory, but I still didn't notice that and just added this directory as well. (I'm not sure what exactly I typed, but at the time it seemed to me that everything now was done, though I still stayed a little curious why that adding at the top didn't add everything; but I dropped the thought then.)

Now I noticed that cloning that outer repository does not check out the files in the inner repository. After some investigation I found that the inner repository seems to be a submodule of the outer, but somehow not a proper one.

Things like git submodule or git status or git log never mention that inner repository but trying to add a file from the inner repository into the outer repository always states: fatal: Path 'path/to/innerRepository/somefile' is in submodule 'path/to/innerRepository', even If I remove the inner .git directory.

What I would like to achieve now is get rid of the information that the directory of the inner repository (and all its contents) is part of another repository. I want to forget the old repository and check the files into the new repository.

How can I do that?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Alfe
  • 56,346
  • 20
  • 107
  • 159

1 Answers1

1

Removing the inner .git folder won't be enough to convince the parent repo that a certain path isn't a submodule.

path/to/innerRepository is probably recorded in the index the the parent repo as a special entry (mode 160000)

Try

git submodule deinit path/to/innerRepository

(it should fail if you don't have .gitmodules)

And:

git rm --cached path/to/innerRepository  # no trailing slash

The last command should make your parent repo "forget" about that submodule.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I read about `deinit` somewhere else before asking here; sorry I didn't mention. The `deinit` line you proposed results in an error: `error: pathspec 'deinit' did not match any file(s) known to git.` Looks like my git version (1.7.9.5) is too old to know that command? – Alfe Jul 21 '14 at 08:08
  • @Alfe yes, upgrading would be nice. But don't forget this command *will* fail anyway if you don't have a `.gitmodules` file. The most important command is the `git rm --cached`: that is the one which mattters here. – VonC Jul 21 '14 at 08:09
  • Will that `git rm` actually remove any files? Since they aren't "known" to git, I assume it won't remove files, right? – Alfe Jul 21 '14 at 08:10
  • 1
    @Alfe no! `git rm --cached` only remove from the index, not from your disk. and remember: no trailing slash. `git rm --cached path/to/innerRepository` – VonC Jul 21 '14 at 08:11
  • @Alfe did you try it? Did it work? Is the status gone? – VonC Jul 21 '14 at 08:13
  • Perfect, thanks a lot! After removing the `.git` dir of the inner repository (I reinstalled it, so I had to remove it again), and `git add path/to/innerRepository` I now have a lot of "new" files in the outer repository :-) – Alfe Jul 21 '14 at 08:14