如何将 Git 中的文件添加到前一个子模块的路径中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16574625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:32:07  来源:igfitidea点击:

How do I add files in Git to the path of a former submodule?

gitgit-submodules

提问by Chris B.

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 .gitmodulesfile and committed the change. I also deleted the .gitdirectory from the mysubmodulefolder.

我有一个用于包含子模块的项目,位于 path mysubmodule。我从源代码 (1.8.3-rc2) 安装了最新的 Git 并运行了git submodule deinit mysubmodule. 然后我删除了.gitmodules文件并提交了更改。我也.gitmysubmodule文件夹中删除了目录。

I'd like to commit the files from mysubmoduleinto my repo directly now, but git says there are no changes. If I type git add mysubmoduleit does nothing. If I type git add mysubmodule/file.txtit says fatal: Path 'mysubmodule/file.txt' is in submodule 'mysubmodule'

我想mysubmodule现在直接将文件提交到我的 repo 中,但是 git 说没有任何更改。如果我输入git add mysubmodule它什么都不做。如果我输入git add mysubmodule/file.txt它说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 mysubmoduledirectory, despite having no .gitmodulesfile. And running git submodule initgives you a No submodule mapping found in .gitmodules for path 'mysubmodule'error.

我还发现,如果您查看 repo 的新版本,它会创建一个mysubmodule目录,尽管没有.gitmodules文件。运行git submodule init会给你一个No submodule mapping found in .gitmodules for path 'mysubmodule'错误。

How do I fix this?

我该如何解决?

回答by VonC

Git still think mysubmoduleis 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 仍然认为mysubmodule是一个子模块,因为它以特殊模式“160000”记录在索引中。
有关更多信息,请参阅“最初只需要 git submodule update?”。
要检查这一点,如在此答案中所示,您可以执行以下操作:

 $ git ls-tree HEAD mysubmodule 
 160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398  mysubmodule 

That doesn't depend on the presence of the .gitmodulefile, or on the content of mysubmodule.

这不取决于.gitmodule文件是否存在,也不取决于mysubmodule.

You need to remove that entry from the index first:

您需要先从索引中删除该条目:

 git rm --cached mysubmodule

Then you can proceed.

然后你可以继续。