Caution! Just lost nested child repo by doing checkout on parent

ε祈祈猫儿з 提交于 2020-01-03 00:19:31

问题


Up until recently, I had this file structure:

-Repo A
 |- .git
 |- files
 |- Repo B
    |- .git
    |- files

I then casually checked out a different branch on Repo A (simply switched branches in Github for Mac), immediately switched back, and voilà:

-Repo A
 |- .git
 |- files
 |- Repo B

Repo B is there but empty! Not even a .git directory!

No remotes, and there goes 2 weeks of 3D modelling.

(The irony of it all is that my very first 3D-model (before all of this) went corrupt so I figured I'd use git and commit on a regular basis. And so I did...)


回答1:


A nested git repo is only recorded as a gitlink, that is a special entry in the index of the main repo.

When you checkout back to your original branch, Git restores the gitlink, but has no idea to which repo that SHA1 is coming from.

To keep both SHA1 and content, you would need to declare repo B as a submodule.
Then you would have a .gitmodules file in the main repo A, which would keep a record of the repo B remote origin url.



来源:https://stackoverflow.com/questions/41967835/caution-just-lost-nested-child-repo-by-doing-checkout-on-parent

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