git submodule not working after deleting

a 夏天 提交于 2020-01-14 01:44:54

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/15483276/git-submodule-not-working-after-deleting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!