如何删除中间子模块但保留叶子子模块?

问题描述 投票:0回答:1

我有三层 Git 子模块,我们将其称为 root、middle 和 leaf。 Leaf是middle的子模块,middle是root的子模块。

我希望删除 middle 作为子模块,并使 leaf 成为 root 的直接子模块,同时保留所有文件和目录结构:

# Before:
root <-- middle <-- leaf

# After:
root <-- leaf

# While directory structure kept both before and after:
root/middle/leaf

遵循这个相关的 StackOverflow 线程会产生奇怪的结果:

# Remove middle submodule:
cd root
git rm --cached middle
git rm .gitmodules

rm -rf middle/.git
rm -rf middle/.gitmodules
rm -rf middle/leaf # remove leaf entirely

git add middle
git commit -m "remove middle submodule"

# Add leaf as submodule of root instead of middle:
git submodule add https://<url-to>/leaf.git middle/leaf

错误:

fatal: Pathspec 'middle/leaf' is in submodule 'middle'

我还尝试首先删除作为 middle 的子模块的 leaf,然后删除作为 root 的子模块的 middle,然后添加 leaf 作为 root 的子模块。同样的错误。

我该怎么办?我很茫然。

git git-submodules
1个回答
0
投票

完整的子模块删除应包括

rm -rf .git/modules/<path-to-submodule>
,请参阅如何删除子模块?

rm -rf .git/modules/middle
之前运行
git submodule add
(或在
git rm --cached middle
之后的某个位置)。

© www.soinside.com 2019 - 2024. All rights reserved.