如何从没有子模块的分支中签出带有子模块的分支

JAM*_*JAM 8 git git-submodules

我的本地计算机上有三个分支:

  • 掌握
  • 带有子模块的功能分支
  • 无子模块的功能分支

没有子模块的分支曾经有一个子模块,我按照此 SO post中的说明删除了该子模块。我不想从master和中删除子模块feature-branch-with-submodule

然而,现在我已经完成了feature-branch-without-submodule,我想切换到feature-branch-with-submodule。所以我执行git checkout,但收到错误:

fatal: not a git repository: src/vendor/mysubmodule/../../../../../.git/modules/src/vendor/mysubmodule
Run Code Online (Sandbox Code Playgroud)

如何修复它,以便带有子模块的分支有它,而没有子模块的分支没有,并且我可以使用 git checkout 自由地来回切换?

kik*_*que 6

一两天来我一直在想问题出在哪里。这是迄今为止我找到的最近似(而且非常糟糕)答案的链接:

具有不同子模块的签出分支不起作用

快速回答:

Supposing, for example, branch master has submodule A and branch alpha has submodule B.

To properly checkout master you should, essentially
git submodule deinit .
git checkout master
git submodule update --init --recursive

To go back to alpha, again
git submodule deinit .
git checkout alpha
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)