git - 如何修复 git 中损坏的子模块配置?

标签 git git-submodules

我在创建子模块时遇到了这个 git 错误。我最初在命令中有一个错误的 URL,现在任何额外的运行都会显示此错误。有什么问题吗?

$ git submodule add -f https://github.com/Shougo/vimproc.vim.git .vim/bundle/vimproc
Adding existing repo at '.vim/bundle/vimproc' to the index
fatal: Not a git repository: .vim/bundle/vimproc/../../../.git/modules/.vim/bundle/vimproc
Failed to add submodule '.vim/bundle/vimproc'

最佳答案

也许子模块已添加到索引中。您应该将它们从索引中删除。

要完全删除子模块,请执行以下步骤:

1 从 .git/config 中删除这些行

[submodule ".vim/bundle/vimproc"]
    url = https://github.com/Shougo/vimproc.vim.git

2 从 .gitmodules 中删除这些行

[submodule ".vim/bundle/vimproc"]
    path = .vim/bundle/vimproc
    url = https://github.com/Shougo/vimproc.vim.git

3 移除子模块目录

rm -rf .vim/bundle/vimproc

4 unstage 子模块

git rm --cached .vim/bundle/vimproc

5 删除.git/modules中的子模块目录

rm -rf .git/modules/.vim/bundle/vimproc

最后,再次添加子模块。

关于git - 如何修复 git 中损坏的子模块配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19508849/

相关文章:

Git - 将更改从子模块推送到主模块?

git - 在 vim 中的 git 提交消息中添加井号/井号作为第一个字符

javascript - React.js 错误 : Invariant Violation: Minified React error #37

在不同的 IDE 中使用 Git 进行 C++ 协作

python - Microsoft azure devops python 管道失败,Bash 退出,代码为 '5'

推送 : object 15abe3addde5ad5f7d25e8f0f220d2e9faf3cb22:contains entries pointing to null 时出现 Git 错误

rebase期间的git子模块冲突导致提交消失

git - 致命的 : The remote end hung up unexpectedly with a fetch upstream

git 子模块 : customization

Git 子模块 : Is it possible to have more than one URL for each?