如何将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
目录。
我想直接将 mysubmodule
中的文件直接提交到我的回购库中,但git说没有任何更改。如果我输入 git add mysubmodule
,它什么也不做。如果我键入 git add mysubmodule / file.txt
它表示 fatal:Path'mysubmodule / file.txt'位于子模块'mysubmodule'中
$ b
我也发现如果你检出新版本的repo,它会创建一个 mysubmodule
目录,尽管没有 .gitmodules
文件。并且运行 git submodule init
会给你一个在.gitmodules中找不到路径'mysubmodule'
错误中找到的子模块映射。 p>
我该如何解决这个问题?解决方案
$ c> mysubmodule 是一个子模块,因为它以特殊模式160000记录在索引中。
请参阅 git子模块更新只需要最初?为更多。
检查,作为在此答案中,您可以执行以下操作:
<$ p $
$ git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398 mysubmodule
<这不取决于 .gitmodule
文件的存在,也不取决于 mysubmodule
的内容。
您需要删除该条目首先指数:
git rm --cached mysubmodule
然后您可以继续。
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.
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'
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 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
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
Then you can proceed.
这篇关于如何将Git中的文件添加到以前的子模块的路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!