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

标签 git github git-submodules repository git-add

我正在为我的 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/

相关文章:

github - 如何找到更多人关注的github项目?

git - 是否可以让 Git 知道现有的 .gitmodules 文件?

git - 将子模块列表添加到 git

java - 使用 JGit 将子模块添加到非空路径

bash - 从 git hook 调用脚本

git 状态给我一个错误 : bad index file sha1 signature

git - Xcode 5 : Pushing and pulling from new GitHub repository does not work

Git - 如何删除一个分支?

如果起源/开发不同步,git flow 功能完成不会推送

git - merge PR 时如何在 GitHub 上创建标签?