我们的团队已经很长时间没有使用子模块了,我们希望通过删除所有缓存的子模块来释放一些存储库空间。
我们是否只需要删除以下内容?
rm -rf .git/modules
或者有更推荐的方法吗?此外,如果可能,我们希望将删除推送到服务器。
注意:使用 git 2.5.4 和当前状态已将所有内容 merge 到一个分支中。
注意:我们不记得旧提交中使用的子模块的各个名称。
最佳答案
我在关于“不使用子模块”的问题中发现了一个可能的小混淆:是否还有未使用的子模块文件夹,或者这些文件夹是否已经删除并且只剩下缓存?
好吧,我认为我们可以通过首先遵循干净的删除过程来解决这两种情况,然后假设某些操作不正确并执行手动清理。
删除一个子模块的必要步骤在How do I remove a submodule?中有解释。 .但是为了回答这个问题,我们将立即删除所有子模块,而不假设我们知道子模块的名称。
# deinit all submodules from .gitmodules
git submodule deinit .
# remove all submodules (`git rm`) from .gitmodules
git submodule | cut -c43- | while read -r line; do (git rm "$line"); done
# delete all submodule sections from .git/config (`git config --local --remove-section`) by fetching those from .git/config
git config --local -l | grep submodule | sed -e 's/^\(submodule\.[^.]*\)\(.*\)/\1/g' | while read -r line; do (git config --local --remove-section "$line"); done
# manually remove leftovers
rm .gitmodules
rm -rf .git/modules
我不知道服务器同步。它可以在下次提交时自动完成,或者我们可能需要这些命令:
git submodule sync
git submodule update --init --recursive --remote
关于git - 从存储库中删除所有 Git 缓存的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34890313/