2

Alright this is gonna be a bit confusing but please bear with me. Still getting used to git and Im struggling. 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.

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.

So naturally, i couldnt open that react app folder on github cuz from what i learned till now is that its now a "submodule"? Which means theres a git repo within a git repo.

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.

So i git pull my code to see what the differences are, it tells me theres three conflits. Two in two files. Which i fix, no problem. The third conflict is the freaking react app directory. 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 *.

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. 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. I swear thats all i wanna do. Why is this so hard.

Saif eldeen Adel
  • 318
  • 3
  • 15

1 Answers1

1

So naturally, i couldnt open that react app folder on github cuz from what i learned till now is that its now a "submodule"?

That's correct.

Which means theres a git repo within a git repo.

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. 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."

The directions/instructions are just a text file. They're stored in a file named .gitmodules; when you clone R and use git submodule init, Git reads the file and tries to clone S per the instructions. If the instructions in .gitmodules are correct, that produces S. R does not contain S at all: R has just the instructions.

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.

To stop R from thinking that S is a submodule, you must teach Git that it's not. There is a very large (and old, August 2009) StackOverflow question and answer all about this: How do I remove a submodule? The process used to be bad, but has been improved since 2009. See VonC's accepted answer.

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.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Sorry I will ask some dumb questions but I hope you can bear with me. First off thanks for the lengthy answer. Makes a little more sense now. However what im struggling to find tho is the `.gitmodules` file, i dont have one inside the **R** and the **S** folder is already deleted. I will check out the answers for removing a submodule, it looks hella confusing, i hope i can figure it out. – Saif eldeen Adel Apr 29 '21 at 09:59
  • And i never initialised a submodule. Do i need to clone the repo from github that has that submodule folder? and then carry out those removal instructions? How would i be able to push my changes from there though – Saif eldeen Adel Apr 29 '21 at 10:02
  • 1
    Run the `git submodule deinit` anyway; if it complains, there's no harm done. Then run the `rm -rf .git/modules/a/submodule` (replace `a/submodule` with the name of the submodule, in this case, `frontend/financee-app`), assuming you're on a Unix-like system so that you have `rm`. With the `-f` it won't complain, even if it does nothing. It's likely that both of these first two steps do nothing, at this point. The payoff will happen with step 3: `git rm -f a/submodule` (again, you'd replace these with `frontend/financee-app` in this case). – torek Apr 29 '21 at 10:12
  • You are a life saver. The answer you linked. That was it. I did run the deinit anyway and i did remove the folder. I then replaced it with the backup folder i had which is pretty much the same folder. And then committed and pushed. No problems. Thank you so much. Its been hours. One thing that was weird is that i didnt have modules folder so i just skipped that part...cuz id be removing it anyway. And it worked. Thank you so much. Its been hours – Saif eldeen Adel Apr 29 '21 at 10:36