How to recover deleted .git/modules folder
Asked Answered
V

2

5

In my project .git/modules folder got deleted. Now I am able to reset the parent branch to other versions but submodule update is not working.

Error I am receiving:

fatal: Not a git repository: ../.git/modules/abc.
Unable to find current revision in submodule path 'abc'

How can I recover the deleted folder and bring back the submodule in line with parent branch.

Repo structure is like this:

parent_folder---|---abc
                |---def

abc and def are submodules.

Vivianna answered 2/5, 2016 at 12:2 Comment(0)
F
5

You have to init & update the submodules again,

git submodule init
git submodule update

It should download and update the current submodules code.

If its still doesnt work try to remove the submodule and add it again with the

git submodule add <params>

And if this doesn't resolve it , add the submodule with the --force flag

If --force is specified, the submodule will be checked out (using git checkout --force if appropriate), even if the commit specified in the index of the containing repository already matches the commit checked out in the submodule.

Fantinlatour answered 2/5, 2016 at 13:4 Comment(3)
First method didnt work. Also while adding the submodule it gave an error saying index already exists. So I deleted everything and did submodule init and submodule update. Code came but I lost previous branches in submodule. Is there any way to recover that?Vivianna
Have you deleted the folder? if you deleted the content you will have to pull them from the serverFantinlatour
Yes I deleted the abc and def folder as mentioned in the example. I had few working branches in abc folder but I didn't do git push.Vivianna
C
0

I am extending on CodeWizard's answer.

If you get

fatal: No URL for Submodul-Path 'app/design/Foo/Bar' in .gitmodules found

Then execute git rm app/design/Foo/Bar or git rm --cached app/design/Foo/Bar and try again.

If you then get

fatal: Could not find repository-handle for Submodul 'app/code/Foo/Bar'.

Then it is probably because you deleted the folder in .git/modules.

The submodules .git file in app/code/Foo/bar is just a "fake" file which references the real git repo in .git/modules. It is not a real repository. If you open it, you see:

gitdir: ../../../../.git/modules/app/code/Foo/Bar

So just delete the folder "app/code/Foo/Bar" and try again.

Calorimeter answered 4/3, 2020 at 12:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.