问题描述
我有一个大目录〜/.vim
,并且在其中有一个带有许多其他git repos的子目录.我想创建我的〜/.vim
目录的git repo,但是不想遍历我的其他git子目录.
I have a big Directory ~/.vim
and in it I have a subdirectory with many other git repos in it. I want to make a git repo of my ~/.vim
directory though, but don't want to go through each of my other git subdirectories.
有什么方法可以递归地遍历并添加所有子模块吗?
Is there any way of just recursively going through and adding all submodules?
推荐答案
假设..vim已经是有效的git存储库,并且您要将所有git存储库添加到您的主要git仓库,那么下面的for循环可能就是您所需要的:
Suppose that .vim is already a valid git repo and your want to add all git repos to your main git repo, then the for loop below is probably what you need:
首先, cd
到您的 git存储库的根目录.
First, cd
to the root of your git repository.
可粘贴的预览命令-仅回显,不会做任何更改:
Paste-able preview command- echo only, won't make any changes:
for x in $(find . -type d) ; do if [ -d "${x}/.git" ] ; then cd "${x}" ; origin="$(git config --get remote.origin.url)" ; cd - 1>/dev/null; echo git submodule add "${origin}" "${x}" ; fi ; done
可粘贴命令以添加子模块:
Paste-able command to add the submodules:
for x in $(find . -type d) ; do if [ -d "${x}/.git" ] ; then cd "${x}" ; origin="$(git config --get remote.origin.url)" ; cd - 1>/dev/null; git submodule add "${origin}" "${x}" ; fi ; done
此循环首先仅查找目录,查找.git目录,标识原始URL,然后添加子模块.
This loop first finds directories only, looks for a .git directory, identifies the original URL and then adds the submodule.
可读版本:
for x in $(find . -type d) ; do
if [ -d "${x}/.git" ] ; then
cd "${x}"
origin="$(git config --get remote.origin.url)"
cd - 1>/dev/null
git submodule add "${origin}" "${x}"
fi
done
这篇关于自动将所有子模块添加到存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!