5

I'm trying to remove submodule from my repo. This are the steps I'm using to remove the repo:

Delete the relevant section from the .gitmodules file. Stage the .gitmodules changes git add .gitmodules Delete the relevant section from .git/config. Run git rm --cached path_to_submodule 

But when I ran this command git rm --cached path_to_submodule I get this error:

fatal: Please stage your changes to .gitmodules or stash them to proceed 

If ran git status I get this message:

fatal: Not a git repository:path to submodule 

Any of you knows why or how can I remove the submodule?

I'll really appreciate your help.

2 Answers 2

6

You might need to first unregister the submodule.

git submodule deinit <path_to_submodule> 
Sign up to request clarification or add additional context in comments.

Comments

1

Removing a submodule (deinit) might not be enough.

Before Git 2.25.2 (March 2020), Running "git rm" (or deinit) on a submodule failed unnecessarily when .gitmodules is only cache-dirty, which has been corrected.

See commit 7edee32 (27 Jan 2020) by David Turner (csusbdt).
(Merged by Junio C Hamano -- gitster -- in commit a74c387, 12 Feb 2020)

git rm submodule: succeed if .gitmodules index stat info is zero

Signed-off-by: David Turner
Reported-by: Thomas Bétous

The bug was that ie_match_stat() was used to compare if the stat info for the file was compatible with the stat info in the index, rather using ie_modified() to check if the file was in fact different from the version in the index.

A version of this (with deinit instead of rm) was reported here.

$ git submodule deinit Submodule1 fatal: Please stage your changes to .gitmodules or stash them to proceed Submodule work tree 'Submodule1' contains local modifications; use '-f' to discard them 

It seems that in that case, the user's clone command left the index with empty stat info.

The mailing list was unable to reproduce this.
But we (Two Sigma) hit the bug while using some plumbing commands, so I'm fixing it.

I manually confirmed that the fix also repairs deinit in this scenario.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.