Git使用现有Git存储库添加文件夹

Bry*_*yan 8 git github repository git-add git-submodules

我正在为我的MacVim安装创建一个git存储库.我的存储库中的一些插件有自己的.git文件夹和repo.问题是......当我尝试将其中一个文件夹添加到我的主存储库时,它什么也没做.

我猜:

我无法添加该文件夹,因为它本身就是一个git repo.我必须添加为子模块或删除.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")
Run Code Online (Sandbox Code Playgroud)

ran*_*909 4

看起来您可能已正确地将这些存储库添加为子模块,但您已更改/添加/删除了这些存储库中的文件。如果你进入bundle/nerdtree并执行“git status”,它应该告诉你有什么不同。如果您使子模块恢复到干净状态,则顶层模块应该停止说“修改内容”

另外,你的命令:

git submodule add bundle/YouCompleteMe/
Run Code Online (Sandbox Code Playgroud)

是不正确的。'git submodule add' 接受一个 repo url,如下所示:

git submodule add https://github.com/Valloric/YouCompleteMe.git
Run Code Online (Sandbox Code Playgroud)

但从你的输出来看,你似乎已经在某个时候正确地完成了这一点。您似乎正在使用 Pathogen 来管理您的子模块 - 它的文档应该可以很好地引导您完成这个过程。或者你可以切换到 Vundle,它显然有一些优势(我个人仍然使用 Pathogen)。