Git 管理分支上的子模块?

Git manage submodule on branch?

我在一个开发分支上有一个子模块,它在其他分支上不存在。每次我切换分支时,我都会收到这样的消息:

warning: unable to rmdir master/images/development/fakeapi: Directory not empty

当我查看目录时,即使我切换到没有子模块的分支,子模块文件仍然存在。

有什么办法可以解决这个问题,这样我就不必在切换分支后手动删除子模块文件了吗?

这似乎记录在 Issues with Submodules 中,它默认涉及一些手动命令。

Switching branches with submodules in them can also be tricky.
If you create a new branch, add a submodule there, and then switch back to a branch without that submodule, you still have the submodule directory as an untracked directory

Solution: git clean -ffd <submodule>

If you do remove that directory and then switch back to the branch that has that submodule, you will need to run submodule update --init to repopulate it.

您在“Working with Git Submodules in MantisBT”中有更多关于这些操作的信息

Is there a way to deal with this so I don't have to manually remove the submodule files after switching branches?


Is there a way to deal with this so I don't have to manually remove the submodule files after switching branches?

检查 git checkout -f 是否可以提供帮助