我已经阅读了如何自己删除git子模块:
# Delete the relevant section from the .gitmodules file.
git config -f .gitmodules --remove-section submodule.$submodulepath
# Delete the relevant section from .git/config
git config -f .git/config --remove-section submodule.$submodulepath
git rm --cached path_to_submodule # no trailing slash
git commit
rm -rf path_to_submodule
我可以做到。但是当其他人执行
git pull
时,我们如何确保子模块从他们的系统中被移除?根据我所知,.gitmodules
的更改会随着拉取而来,但似乎没有太多其他的变化。因此,拉取代码的人仍然需要运行以下命令:git config -f .git/config --remove-section submodule.$submodulepath
rm -rf path_to_submodule
这样对吗?在一个小的开发团队中,你可能只需要告诉每个人运行这些命令,但这不是最理想的选择。
有没有某个神奇的命令可以自动化处理呢?特别是我希望在部署脚本中有一种标准的自动化方式。从我的记忆中,我不确定脚本怎么知道以前的子模块数目是否减少了。(不是特别吸引人的)选项包括:
- 在拉取前后对
.gitmodules
进行比较 - 删除所有子模块,然后在每个部署上运行
git submodule update --init
- 拉取后子模块变成了未跟踪的文件,所以一种可行的方法是在拉取后删除所有包含
.git
子目录的未跟踪目录,但这种方法会误删你想要保留的东西。
如果有更好的选项,请提出。
git rm
命令不应该在拉取时删除子模型吗? - Daniel Hilgarthgit clean -df
对你来说是一个选项吗?它会删除所有未被跟踪的内容。 - CharlesB