Git: Removing submodule error
Asked Answered
P

2

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.

Parchment answered 4/5, 2017 at 17:20 Comment(0)
C
6

You might need to first unregister the submodule.

git submodule deinit <path_to_submodule>  
Chalcidice answered 4/5, 2017 at 17:33 Comment(0)
S
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.

Skewer answered 13/2, 2020 at 17:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.