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

编程入门 行业动态 更新时间:2024-10-21 20:26:38
本文介绍了如何将 Git 中的文件添加到前一个子模块的路径中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个项目,它曾经包含一个子模块,位于路径 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 中的文件添加到前一个子模块的路径中?

本文发布于:2023-11-23 15:55:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622035.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   个子   路径   模块   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!