Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git thinks some copied code is a submodule

In an effort to debug a problem in a third party library, I copied their source into my own git repo. I reproduced the problem immediately so wanted to commit to record a starting point. When I attempted to commit, none of the files I had copied were showing up in my working tree, so I couldn't stage them.

I tried explicitly staging one of the files in the copied source:

git add README 
fatal: Path 'Src/Foo/README' is in submodule 'Src/Foo/FooBar'

So it seems git thinks it's a submodule, even though I never told it that it was. I tried deleting the .git directory in the root of the third party source, but that didn't help. Then I tried following these instructions, but it tells me I have no submodules:

git submodule deinit .
No submodule mapping found in .gitmodules for path 'Src/Foo/FooBar'

Any ideas?

like image 803
me-- Avatar asked Mar 08 '14 03:03

me--


People also ask

Why do people dislike git submodules?

You can't just clone the repo any more, you have to clone recursively. You can't just checkout branches any more, you have to init and update the submodules too, with extra complications if the same submodules don't exist in all branches. You can't just commit/push, you have to commit/push the submodules first.


1 Answers

The simplest solution is to clone that third-party repo, reproduces your fix, commit and push (if you have access to their repo, you if you have forked it on GitHub)

If not, do (in a fresh clone of your repo) a:

git ls-tree HEAD Src/Foo/FooBar

See if there is an special entry 160000, which would indicate that FooBar was registered as a submodule at one point in time) even if the .gitmodules doesn't list FooBar anymore.

A git rm --cached Src/Foo/FooBar (with git 1.8.5+) would take care of that submodule entry.


Of course, if the thirdparty sources are not part of a git repo, then adding them in a different folder within your own repo would work too.
But the history of those third-party library files would become mixed with the history of your main repo.

like image 139
VonC Avatar answered Oct 04 '22 00:10

VonC