Git:删除子模块错误

5

我正在尝试从我的仓库中删除子模块。这是我用来删除仓库的步骤:

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

有没有人知道为什么或如何移除子模块?

非常感谢你的帮助。

2个回答

6
您可能需要首先注销子模块。
git submodule deinit <path_to_submodule>  

1

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

在 Git 2.25.2(2020 年 3 月)之前,当 .gitmodules 只是缓存脏数据时,运行 "git rm"(或 deinit)会失败,这已经得到了纠正。

请参见 commit 7edee32(2020 年 1 月 27 日),作者为 David Turner (csusbdt)
(由 Junio C Hamano -- gitster --commit a74c387 中合并)

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.


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接