Git 子模块混乱

Git submodules confusion

我创建了一个新项目,其中包含一些已有 git 存储库的文件夹。

编辑:内部 git 存储库没有上传到网上某处,也没有在其中进行提交,仅在主存储库中

当我为初始提交添加所有带有 git add --all 的文件并将它们推送到 bitbucket 时,内部 git 跟踪文件夹不存在于 s 中,而是 link- like 条目被列为字母数字,如 sha hash like

<folder name> → 031c27df078f [031c27df078f]

经过一番困惑后,我最终删除了我的本地文件以及子模块中的 .git 子文件夹。

我努力重置为我的第一次提交,但没有文件被还原。

有什么方法可以从我的主要 git 存储库中取回我的更改,还是它们会永远丢失?

有没有办法推送包括子模块在内的所有文件夹?

the inner git tracked folder was not present in the s but instead a link-like entry was listed with an alphanumeric like a sha hash

那些不是子模块,而是简单的 gitlink (special entries in the index) 表示嵌套的 git repo SHA1。
参见“”。

Is there any way to get my changes back from my main git repo or are they forever lost?

至少克隆回您的存储库(您推送 git 链接 + 您的代码的存储库):您会在那里找到您的更改。

然后在新的 repo 中重新开始,并强制推送。


is there any way to get the inner repo(which now is a link) to the state it was when i pushed the code to bitbucket?

你有那些内部回购的 SHA1,希望你有他们的 url。

因此,在您全新的存储库中,一旦您添加并提交了自己的代码,这次将这些存储库添加为子模块:

 cd /path/to/new/repo
 git submodule add -- /url/repo1
 cd repo1
 git checkout <SHA1>
 cd ..
 git add repo1 # no trailing slash
 git commit -m "add repo1 as submodule"
 git push -u origin master

但是,OP 确实提到:

I still have the files in the initial state. But all my changes were done in the pasted one. Another big mistake was that my only commit was on the main repo when i created it. The inner one was in the initial state.

在那种情况下(没有内部 .git 文件夹),这些机会可能会丢失。