如何将 Git 中的文件添加到前一个子模块的路径中? [英] How do I add files in Git to the path of a former submodule?
问题描述
我有一个项目,它曾经包含一个子模块,位于路径 mysubmodule
.我从源代码 (1.8.3-rc2) 安装了最新的 Git 并运行 git submodule deinit mysubmodule
.然后我删除了 .gitmodules
文件并提交了更改.我还从 mysubmodule
文件夹中删除了 .git
目录.
I have a project that used to contain a submodule, at path mysubmodule
. I installed the latest Git from source (1.8.3-rc2) and ran git submodule deinit mysubmodule
. I then deleted the .gitmodules
file and committed the change. I also deleted the .git
directory from the mysubmodule
folder.
我现在想将 mysubmodule
中的文件直接提交到我的存储库中,但是 git 说没有任何更改.如果我输入 git add mysubmodule
它什么都不做.如果我输入 git add mysubmodule/file.txt
它说 fatal: Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'
I'd like to commit the files from mysubmodule
into my repo directly now, but git says there are no changes. If I type git add mysubmodule
it does nothing. If I type git add mysubmodule/file.txt
it says fatal: Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'
我还发现,如果您查看新版本的 repo,它会创建一个 mysubmodule
目录,尽管没有 .gitmodules
文件.并且运行 git submodule init
会给你一个 No submodule mapping found in .gitmodules for path 'mysubmodule'
错误.
I've also discovered if you check out a fresh version of the repo, it creates a mysubmodule
directory, despite having no .gitmodules
file. And running git submodule init
gives you a No submodule mapping found in .gitmodules for path 'mysubmodule'
error.
我该如何解决这个问题?
How do I fix this?
推荐答案
Git 仍然认为 mysubmodule
是一个子模块,因为它在索引中以特殊模式160000"记录.
有关更多信息,请参阅git 子模块更新仅最初需要?".
要检查这一点,如本答案中所述,您可以执行以下操作:
Git still think mysubmodule
is a submodule, because it is recorded in the index with a special mode "160000".
See "git submodule update needed only initially?" for more.
To check that, as in in this answer, you can do a:
$ git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
这不依赖于 .gitmodule
文件的存在,也不依赖于 mysubmodule
的内容.
That doesn't depend on the presence of the .gitmodule
file, or on the content of mysubmodule
.
您需要先从索引中删除该条目:
You need to remove that entry from the index first:
git rm --cached mysubmodule
然后你就可以继续了.
这篇关于如何将 Git 中的文件添加到前一个子模块的路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!