How do I add files in Git to the path of a former submodule?
Asked Answered
S

1

74

I have a project that used to contain a submodule, at path mysubmodule. I installed the latest Git from source (1.8.3-rc2) and ran git submodule deinit mysubmodule. I then deleted the .gitmodules file and committed the change. I also deleted the .git directory from the mysubmodule folder.

I'd like to commit the files from mysubmodule into my repo directly now, but git says there are no changes. If I type git add mysubmodule it does nothing. If I type git add mysubmodule/file.txt it says fatal: Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'

I've also discovered if you check out a fresh version of the repo, it creates a mysubmodule directory, despite having no .gitmodules file. And running git submodule init gives you a No submodule mapping found in .gitmodules for path 'mysubmodule' error.

How do I fix this?

Sheridansherie answered 15/5, 2013 at 20:42 Comment(1)
Have you checked all of these steps to ensure there are no parts of the submodule lingering around? I don't think deinit entirely removes the submodule. It appears to simply remove it from your .git/config file, as though you'd cloned a repo with a submodule, but had not yet run git init. That's different than entirely removing the submodule. If this is the case, git still thinks that folder is a submodule, but is ignoring it.Sotelo
K
99

Git still think mysubmodule is a submodule, because it is recorded in the index with a special mode "160000".
See "git submodule update needed only initially?" for more.
To check that, as in in this answer, you can do a:

 $ git ls-tree HEAD mysubmodule 
 160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398  mysubmodule 

That doesn't depend on the presence of the .gitmodule file, or on the content of mysubmodule.

You need to remove that entry from the index first:

 git rm --cached mysubmodule

Then you can proceed.

Kyles answered 16/5, 2013 at 7:9 Comment(2)
git ls-tree HEAD mysubmodule gave me no results but git ls-files --stage | grep mysubmodule worked. Reference. Why would that be?Icecap
@Icecap Not sure: I just tested both, and they work. What git version are you using, on which OS?Kyles

© 2022 - 2024 — McMap. All rights reserved.