Git: 移除子模块错误

Git: Removing submodule error

我正在尝试从我的存储库中删除子模块。这是我用来删除 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 

但是当我 运行 这个命令 git rm --cached path_to_submodule 我得到这个错误:

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

如果 运行 git status 我收到此消息:

fatal: Not a git repository:path to submodule

你们中有人知道为什么或如何删除子模块吗?

非常感谢你的帮助。

您可能需要先注销子模块。

git submodule deinit <path_to_submodule>  

删除子模块 (deinit) 可能还不够。

在 Git 2.25.2(2020 年 3 月)之前,当 .gitmodules 只是缓存时,子模块上的 运行“git rm”(或 deinit)不必要地失败-脏,已更正。

commit 7edee32 (27 Jan 2020) by David Turner (csusbdt)
(由 Junio C Hamano -- gitster -- in commit a74c387 合并,2020 年 2 月 12 日)

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.