简体   繁体   English

如何恢复已删除的 .git/modules 文件夹

[英]How to recover deleted .git/modules folder

In my project .git/modules folder got deleted.在我的项目中 .git/modules 文件夹被删除了。 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. abc 和 def 是子模块。

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如果这不能解决它,请添加带有--force标志的子模块

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.如果指定了--force ,子模块将被检出(如果合适,使用 git checkout --force),即使包含存储库的索引中指定的提交已经与子模块中检出的提交匹配。

I am extending on CodeWizard's answer.我正在扩展 CodeWizard 的答案。

If you get如果你得到

fatal : No URL for Submodul-Path 'app/design/Foo/Bar' in .gitmodules found致命:在 .gitmodules 中找不到 Submodul-Path 'app/design/Foo/Bar' 的 URL

Then execute git rm app/design/Foo/Bar or git rm --cached app/design/Foo/Bar and try again.然后执行git rm app/design/Foo/Bargit rm --cached app/design/Foo/Bar试。

If you then get如果你然后得到

fatal : Could not find repository-handle for Submodul 'app/code/Foo/Bar'.致命:找不到子模块“app/code/Foo/Bar”的存储库句柄。

Then it is probably because you deleted the folder in .git/modules.那么可能是因为你删除了 .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 . app/code/Foo/bar 中的子模块.git文件只是一个“假”文件,它引用了.git/modules 中的真实 git repo。 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.所以只需删除文件夹“ app/code/Foo/Bar ”,然后再试一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM