我正在为我的 MacVim 安装创建一个 git 存储库。我存储库中的一些插件有自己的 .git 文件夹和存储库。问题是......当我尝试将这些文件夹之一添加到我的主存储库时,它什么也没做。
我的猜测:
我无法添加该文件夹,因为它是一个独立的 git 存储库。我必须添加为子模块或删除 .git 文件夹。
如何将我的子仓库添加为子模块?
bryan-mini:.vim bsaltzman$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: bundle/YouCompleteMe (modified content)
# modified: bundle/nerdtree (modified content)
# modified: bundle/ultisnips (modified content)
#
no changes added to commit (use "git add" and/or "git commit -a")
// This
bryan-mini:.vim bsaltzman$ git add bundle/YouCompleteMe/
// OR THIS
bryan-mini:.vim bsaltzman$ git submodule add bundle/YouCompleteMe/
repo URL: 'bundle/YouCompleteMe/' must be absolute or begin with ./|../
bryan-mini:.vim bsaltzman$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# (commit or discard the untracked or modified content in submodules)
#
# modified: bundle/YouCompleteMe (modified content)
# modified: bundle/nerdtree (modified content)
# modified: bundle/ultisnips (modified content)
#
no changes added to commit (use "git add" and/or "git commit -a")
最佳答案
看起来您可能已将这些存储库正确添加为子模块,但您已经更改/添加/删除了这些存储库中的文件。如果你 cd 进入 bundle/nerdtree 并执行“git status”,它应该会告诉你有什么不同。如果你让子模块回到干净状态,顶层应该停止说“修改内容”
此外,您的命令:
git submodule add bundle/YouCompleteMe/
不正确。 'git submodule add' 接受一个像这样的 repo url:
git submodule add https://github.com/Valloric/YouCompleteMe.git
但是从您的输出来看,您似乎已经在某些时候正确地完成了该操作。您似乎正在使用 Pathogen 来管理您的子模块——它的文档应该会很好地引导您完成这个过程。或者您可以切换到显然具有一些优势的 Vundle(我个人仍在使用 Pathogen)。
关于Git 使用现有的 Git 存储库添加文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19576552/