Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a submodule which can't be removed from the index

I'm trying to add a submodule that already existed (different git remote repository). As I didn't searched before how to do it correctly, I think I've messed up my repository and I need some help to fix it again.

I've already deleted all the relevant sections from the .gitmodules and .git/config regarding the submodules I want to delete. I've also verified that there is not modules directory inside my .git/ directory.

However, when I run the command git rm --cached path_to_submodule, the following message is displayed:

 fatal: pathspec 'path_to_submodule' did not match any files 

As the previous command fails, when I try to add again the same submodule with the new definitions, running the command git submodule add gituser@host:repo.git, this is the displayed message:

 'repo' already exists in the index 
like image 970
Rui Gonçalves Avatar asked Aug 31 '12 15:08

Rui Gonçalves


People also ask

How do I add a submodule to a specific path?

In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.

What does recurse submodules mean?

If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.


1 Answers

The only way that message ('repo' already exists in the index) can be displayed is if 'repo' still exists in the index (see this chapter on submodule):

$ rm -Rf rack/ $ git submodule add [email protected]:schacon/rack.git rack 'rack' already exists in the index  You have to unstage the rack directory first. Then you can add the submodule:  $ git rm -r rack $ git submodule add [email protected]:schacon/rack.git rack 

Even if 'rack' isn't a submodule, if it exists, it would prevent the declaration of a submodule of the same name.

like image 65
VonC Avatar answered Sep 19 '22 13:09

VonC