[英]Git - "<directory> does not have a commit checked out" even after deleting the .git inside that directory. Cant get rid of inner git repo
Alright this is gonna be a bit confusing but please bear with me.好吧,这会有点混乱,但请多多包涵。 Still getting used to git and Im struggling.
仍然习惯于 git 并且我正在苦苦挣扎。 So.
所以。 The sequence of events were as follows (very hectic so ill summarise)
事件的顺序如下(非常忙碌所以总结不出来)
I have a project with backend and frontend.我有一个带有后端和前端的项目。 the frontend directory has a react app (
frontend/financee-app/
) which by default has a .git
initialised in it.前端目录有一个反应应用程序(
frontend/financee-app/
),默认情况下在其中初始化一个.git
。
But my dumb self forgot to delete that inner repo before initialising a git repo for the whole project and committing and pushing my code.但是我愚蠢的自己忘记在为整个项目初始化 git 存储库并提交和推送我的代码之前删除该内部存储库。
So naturally, i couldnt open that react app folder on github cuz from what i learned till now is that its now a "submodule"?所以很自然,我无法打开 github 上的 react app 文件夹,因为从我到现在为止我了解到的是它现在是一个“子模块”? Which means theres a git repo within a git repo.
这意味着 git 存储库中有一个 git 存储库。
But after so many struggles and messing up my files, i replace my files with the backup files i had for this exact reason which have pretty much the same file structure as what i originally committed.但是经过这么多的挣扎和弄乱我的文件后,我用备份文件替换了我的文件,因为这个确切的原因与我最初提交的文件结构几乎相同。 BUT i made sure there is no inner git repo in the react app this time.
但是我确保这次反应应用程序中没有内部 git 回购。
So i git pull my code to see what the differences are, it tells me theres three conflits.所以我 git 拉我的代码,看看有什么区别,它告诉我存在三个冲突。 Two in two files.
两个文件中的两个。 Which i fix, no problem.
我修好了,没问题。 The third conflict is the freaking react app directory.
第三个冲突是该死的 react app 目录。 Idk how to fix it so i just fix the other two, make sure i dont have a git repo in that app directory, and then i finally
git add *
.我知道如何修复它,所以我只修复其他两个,确保我在该应用程序目录中没有 git 存储库,然后我最后
git add *
。
Annnd.安德。 An error.
一个错误。
error: 'frontend/financee-app' does not have a commit checked out
fatal: updating files failed
Searching everywhere about that error, everyone keeps saying to delete the inner git repo.到处搜索有关该错误的信息,每个人都在说要删除内部 git 存储库。 BUT I ALREADY DID.
但我已经做到了。 Is it detecting the one that i mistakenly pushed the first time that caused all these issues?
它是否检测到我第一次错误推送导致所有这些问题的那个? What if i want to get rid of it for good.
如果我想永远摆脱它怎么办。 I just want to commit this new folder that doesnt have the git repo inside.
我只想提交这个没有 git 存储库的新文件夹。 I swear thats all i wanna do.
我发誓这就是我想做的。 Why is this so hard.
为什么这么难。
So naturally, i couldnt open that react app folder on github cuz from what i learned till now is that its now a "submodule"?
所以很自然,我无法打开 github 上的 react app 文件夹,因为从我到现在为止我了解到的是它现在是一个“子模块”?
That's correct.这是正确的。
Which means theres a git repo within a git repo.
这意味着 git 存储库中有一个 git 存储库。
That's... not quite right.这……不太对。 Git can't hold a repository inside a repository—or maybe won't is a better word here, as the reason is only partly technical—so a submodule is not a repository inside a repository, but rather a reference to some repository, inside a repository.
Git不能在存储库中保存存储库——或者在这里可能不是一个更好的词,因为部分原因是技术性的——所以子模块不是存储库中的存储库,而是对某个存储库的引用,在里面一个存储库。 That is, if we designate the outer Git repository as R (repo), and the inner one as S (submodule), what R contains is not S itself, but rather some directions or instructions: "Go find S and clone it. Then, check out commit C inside S ."
也就是说,如果我们将外部的Git存储库指定为R (repo),将内部的存储库指定为S (子模块),则 R包含的不是S本身,而是克隆它。 ,检查S内的提交C 。”
The directions/instructions are just a text file.方向/说明只是一个文本文件。 They're stored in a file named
.gitmodules
;它们存储在一个名为
.gitmodules
的文件中; when you clone R and use git submodule init
, Git reads the file and tries to clone S per the instructions.当您克隆R并使用
git submodule init
, Git 读取文件并尝试按照说明克隆S。 If the instructions in .gitmodules
are correct, that produces S .如果
.gitmodules
中的说明正确,则会产生S 。 R does not contain S at all: R has just the instructions. R根本不包含S : R只有指令。
Having followed the instructions, the setup for, and commits within, repository R now have information recording the submodule-ness of S , and this is where things go wrong.遵循说明、设置和提交,存储库R现在有记录S的子模块的信息,这就是 go 错误的地方。
To stop R from thinking that S is a submodule, you must teach Git that it's not.要阻止R认为S是子模块,您必须告诉 Git 它不是。 There is a very large (and old, August 2009) StackOverflow question and answer all about this: How do I remove a submodule?
有一个非常大的(并且是 2009 年 8 月的旧)StackOverflow 问题和所有关于此的答案:如何删除子模块? The process used to be bad, but has been improved since 2009. See VonC's accepted answer .
该过程过去很糟糕,但自 2009 年以来已得到改进。请参阅VonC 接受的答案。
error: 'frontend/financee-app' does not have a commit checked out fatal: updating files failed
This is the symptom you will see when R still thinks that S exists as a submodule.这是您在R仍然认为S作为子模块存在时会看到的症状。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.