我正在重组我的dotfile,并具有以下目录结构:
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 repos,它们已经被克隆到其目录中。
我现在想控制整个dotfiles目录的版本。
如何将六个.../.git
存储库作为子模块添加到顶级存储库中,而不必重新克隆软件包。
请注意,here是一个类似的问题,但给出的说明不清楚。 我需要的是分步解决方案,将整个.vim目录添加到顶级仓库中。
答案 0 :(得分:4)
这是一个逐步的过程:
# 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 docs中针对子模块here所述,子模块的add命令将path作为可选参数。
git add submodule <repository> [<path>]
可选参数
<path>
是克隆对象的相对位置 子模块存在于超级项目中。如果未提供<path>
,则 使用源存储库的规范部分(“ repo”用于 “ /path/to/repo.git”和“ foo”代表“ host.xz:foo / .git”)。 如果<path>
存在并且已经是一个有效的Git存储库,然后将其暂存 提交而不进行克隆。<path>
也用作子模块的 逻辑名称在其配置条目中,除非--name用于 指定一个逻辑名称。