如何将 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
How do I add files in Git to the path of a former submodule?
提问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 .gitmodules
file and committed the change. I also deleted the .git
directory from the mysubmodule
folder.
我有一个用于包含子模块的项目,位于 path mysubmodule
。我从源代码 (1.8.3-rc2) 安装了最新的 Git 并运行了git submodule deinit mysubmodule
. 然后我删除了.gitmodules
文件并提交了更改。我也.git
从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'
我想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 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.
我还发现,如果您查看 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 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 仍然认为mysubmodule
是一个子模块,因为它以特殊模式“160000”记录在索引中。
有关更多信息,请参阅“最初只需要 git submodule update?”。
要检查这一点,如在此答案中所示,您可以执行以下操作:
$ 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
.
这不取决于.gitmodule
文件是否存在,也不取决于mysubmodule
.
You need to remove that entry from the index first:
您需要先从索引中删除该条目:
git rm --cached mysubmodule
Then you can proceed.
然后你可以继续。