Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trouble with adding/removing a git submodule

I'm trying to add a git submodule to my project, specifically ShareKit. My project is a git repo, and when I try to type

git submodule add git://github.com/ShareKit/ShareKit.git Submodules/ShareKit

into Terminal I got an error saying that the submodule already existed. I guess I added it a while ago to this project, and ended up not using it and improperly deleting it from the project directory (just deleting the submodule folder, most likely). So I try and do

git rm --cached Submodules/ShareKit

according to How do I remove a submodule?, and now when I try and add the submodule again with the first bit of code I get this:

A git directory for 'Submodules/ShareKit' is found locally with remote(s):
origin  git://github.com/ShareKit/ShareKit.git
If you want to reuse this local git directory instead of cloning again from
git://github.com/ShareKit/ShareKit.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

and I'm not really sure what to do. I'm fairly new to git, and I need to get this in my project - is there any way to just wipe everything git related off of the project and start from scratch? I'd just do it with a new project but it's already pretty much complete aside from this and it would be hugely time-consuming to start from scratch and copy everything over. I have ShareKit working in a test app, installed properly, is there any reason I can't just copy all of the ShareKit files from that folder into the one I need them in?

Edit: I have tried

git submodule deinit Submodules/ShareKit

which gives me this error:

error: pathspec 'Submodules/ShareKit' did not match any file(s) known to git.
Did you forget to 'git add'?

It seems like it's stuck in some sort of weird state where it's both insisting that the submodule does and doesn't exist simultaneously. I'm doing this with Terminal to add the submodule to an Xcode project, just to clarify.

like image 341
lunadiviner Avatar asked Nov 11 '13 20:11

lunadiviner


2 Answers

iveqy's comment did the trick for me, posting it as an answer so that it is more visible.

Simply delete the following folder (adjust with your submodule's path):

.git/modules/Submodules/ShareKit

You can delete it with rm path -rf under unix, or to be safe just move it to /tmp (it should be erased on next boot, but gives you time to change your mind if you deleted the wrong folder):

mv .git/modules/Submodules/ShareKit /tmp/ShareKit-deleted
like image 157
Suzanne Soy Avatar answered Sep 28 '22 03:09

Suzanne Soy


Try the following to force git to re-add the submodule:

git submodule add --force git://github.com/ShareKit/ShareKit.git Submodules/ShareKit

Note the --force after add.

If you'd want to remove version handling altogether, simply remove .git and .gitmodules.

like image 45
JBarberU Avatar answered Sep 28 '22 03:09

JBarberU