添加现有 git 回购作为子模块

Add existing git repo as submodule

我正在重组我的点文件并具有以下目录结构:

dotfiles
├── .vim
│   ├── colors/
│   ├── ftplugin/
│   ├── pack/
│   │   └── my_plugins/
│   │       ├── opt/
│   │       │   ├── nerdtree/
│   │       │   │   ├── .git
│   │       │   └── vimwiki/
│   │       │       ├── .git
│   │       └── start/
│   │           ├── fugitive/
│   │           │   ├── .git
│   │           ├── syntastic/
│   │           │   ├── .git
│   │           ├── vimade/
│   │           │   ├── .git
│   │           └── vim-css-color/
│   │               ├── .git
│   ├── README.md
│   └── vimrc

有六个目录是 github 存储库并且已经被克隆到它们的目录中。

我现在想对整个 dotfiles 目录进行版本控制。 如何将六个 .../.git 存储库作为子模块添加到顶级存储库,而无需重新克隆包。

注意here,问过类似的问题,但给出的说明不清楚。 我需要的是将整个 .vim 目录添加到顶级存储库的分步解决方案。

这是一个循序渐进的过程:

# dotfiles directory is current directory
git init 

# Add already cloned repos
git submodule add <github-repo1-link> <path-to-already-cloned-repo1>
git submodule add <github-repo2-link> <path-to-already-cloned-repo2>
.
.
.

# Add other files for staging
git add .

# Commit the changes
git commit

如 git 子模块文档 here 中所述,子模块的添加命令将路径作为可选参数。

git submodule add <repository> [<path>]

The optional argument <path> is the relative location for the cloned submodule to exist in the superproject. If <path> is not given, the canonical part of the source repository is used ("repo" for "/path/to/repo.git" and "foo" for "host.xz:foo/.git"). If <path> exists and is already a valid Git repository, then it is staged for commit without cloning. The <path> is also used as the submodule’s logical name in its configuration entries unless --name is used to specify a logical name.