从存储库中删除所有 Git 缓存的子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34890313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting all Git cached submodules from repository
提问by C?ur
Our team is not using submodules anymore for a long time and we would like to free some repository space by deleting all cached submodules.
我们的团队已经很长时间不再使用子模块了,我们希望通过删除所有缓存的子模块来释放一些存储库空间。
Do we simply need to delete the following?
我们是否只需要删除以下内容?
rm -rf .git/modules
Or is there a more recommended way to do it? Also, we would like the deletion to be pushed to server if possible.
或者有更推荐的方法吗?此外,如果可能,我们希望将删除推送到服务器。
Note: Using git 2.5.4 and current state has everything merged in one branch.
注意:使用 git 2.5.4 和当前状态将所有内容合并到一个分支中。
Note: We do not remember the individual names of submodules that were used in old commits.
注意:我们不记得旧提交中使用的子模块的单独名称。
回答by C?ur
I figured out a possible small confusion in my question regarding "not using submodules": are there unused submodule folders left, or were those folders deleted already and only cache is left?
我在关于“不使用子模块”的问题中发现了一个可能的小困惑:是否还有未使用的子模块文件夹,或者这些文件夹是否已经被删除而只剩下缓存?
Well, I think we can address both situations by first following a clean removal process, and then assume something was not done correctly and perform a manual cleanup.
好吧,我认为我们可以通过首先遵循干净的删除过程来解决这两种情况,然后假设某些事情没有正确完成并执行手动清理。
The necessary steps for deleting one submodule are explained in How do I remove a submodule?. But to answer the question we will remove all submodules at once without assuming we know the names of the submodules.
如何删除子模块?中解释了删除一个子模块的必要步骤。. 但是为了回答这个问题,我们将立即删除所有子模块,而不假设我们知道子模块的名称。
# 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\.[^.]*\)\(.*\)//g' | while read -r line; do (git config --local --remove-section "$line"); done
# manually remove leftovers
rm .gitmodules
rm -rf .git/modules
I do not know for server synchronisation. It could be done automatically with next commit, or we might need those commands:
我不知道服务器同步。它可以在下一次提交时自动完成,或者我们可能需要这些命令:
git submodule sync
git submodule update --init --recursive --remote
回答by J.J. Hakala
With git 2.7
使用 git 2.7
git submodule deinit mysubmod
git rm mysubmod
git commit -m "Remove mysubmod"
git push
rm -rf .git/modules/mysubmod
This updates .gitmodules
and .git/config
and removes mysubmod
and .git
there. Otherwise there will be problems if one wants to have some content in a directory named mysubmod
.
这将更新.gitmodules
和.git/config
删除mysubmod
并.git
在那里。否则,如果想要在名为mysubmod
.
In this case only the last part is left to be done. Since the submodules are basically just pointers to other repositories, there is not much to clean up unless those repositories that have been referred as submodules are to be removed. Working with the old commits of the repository may become more difficult.
在这种情况下,只剩下最后一部分要做。由于子模块基本上只是指向其他存储库的指针,因此除非要删除那些被称为子模块的存储库,否则没有多少要清理的。使用存储库的旧提交可能会变得更加困难。