2

I have a project with a submodule set up. A colleague by accident deleted the target folder and made a symlink instead (pointing outside the project folder), committing it.

Now I'm not able to restore the submodule anymore, even after deleting the link and creating an empty directory. .gitmodule and .git/config haven't changed. git submodule add and git submodule init don't do anything.

I can't revert the problematic commit, because it also contains a lot of other changes.

How can this be fixed?

didi_X8
  • 5,018
  • 10
  • 42
  • 46

2 Answers2

4

You need to restore the directories as they were stored in your repo before the change.

Re-creating those submodule root directory won't work.

What will work is:

git checkout master@{2 days ago} -- path/to/submodule/directory

(if you know the submodule was working 2 days ago, for instance)

That will restore an empty directory which actually is a special entry in the index.

Then a git submodule update --init will restore its content.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

The solution was to remove the submodule target directory and re-add the submodule:

git rm libs/routing
git submodule add ../librouting.git libs/routing
didi_X8
  • 5,018
  • 10
  • 42
  • 46