使用 `git pull --recurse-submodules` 返回空的子模块目录[重复]

问题描述 投票:0回答:1

首先我会要求不要因为我使用 git 而受到评判......它可能不是最佳的,但到目前为止它已经奏效了。目前我正在使用它在我的设备之间同步我所有的大学项目。对于某些课程,我还有子模块,因为这些是我与其他人合作的项目。到目前为止,使用 git 子模块似乎工作得很好而且花花公子,但是对于我添加的最后两个子模块,我可以毫无问题地推送更改,但是在拉动时,包含子模块的目录是完全空的,甚至没有 .git 文件。以下是我尝试过的一些事情及其结果:

PS D:\University> git pull --recurse-submodules
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 5), reused 8 (delta 3), pack-reused 0
Unpacking objects: 100% (10/10), 1.04 KiB | 1024 bytes/s, done.
From https://github.com/**********/University
   0e65e10f..c47ea81b  master     -> origin/master
Fetching submodule Semantics and Rewriting/PokeBattles_project
Fetching submodule Year 2/New Devices Lab/smart-closet
Fetching submodule Year 2/New Devices Lab/smart-shop/final project
From https://github.com/**********/Smart-Shop-Project
   ab09d5a..3304c39  master     -> origin/master
 * [new branch]      dependabot/npm_and_yarn/mongoose-7.0.4 -> origin/dependabot/npm_and_yarn/mongoose-7.0.4
 * [new branch]      dependabot/npm_and_yarn/nodemon-2.0.22 -> origin/dependabot/npm_and_yarn/nodemon-2.0.22
warning: unable to rmdir 'Semantics and Rewriting/PokeBattles_project': Directory not empty
Updating 0e65e10f..c47ea81b
Fast-forward
 .gitmodules                                                        | 7 +++++--
 Human-Computer Interaction/Project/HCI-Project                     | 1 +
 .../{PokeBattles_project => PokeBattle-Project}                    | 0
 3 files changed, 6 insertions(+), 2 deletions(-)
 create mode 160000 Human-Computer Interaction/Project/HCI-Project
 rename Semantics and Rewriting/{PokeBattles_project => PokeBattle-Project} (100%)

PS D:\University> git submodule update --remote
Submodule path 'Year 2/New Devices Lab/smart-shop/final project': checked out '3304c398f204debcafa8e37dd89e038feeb345d2'

PS D:\University> git submodule update --recursive --checkout --remote

PS D:\University> git submodule foreach git pull origin main
Entering 'Year 2/New Devices Lab/smart-closet'
fatal: couldn't find remote ref main
fatal: run_command returned non-zero status for Year 2/New Devices Lab/smart-closet
.

如您所见,我尝试了多种我见过的方法。有问题的两个子模块是“HCI-Project”和“Pokebattle-Project”。 HCI 项目包含一个完整的 Unity 项目,除了一个自述文件和一个 .gitignore,另一个只是一个自述文件。屁股你可以在这里看到,它们完全是空的,甚至没有 .git 文件。正因为如此,如果我再次尝试

git pull --recurse-submodules
,git 甚至似乎都不会尝试从这些回购协议中提取:

PS D:\University> git pull --recurse-submodules
Fetching submodule Year 2/New Devices Lab/smart-closet
Fetching submodule Year 2/New Devices Lab/smart-shop/final project
Fetching submodule Year 2/New Devices Lab/smart-shop/login system
Fetching submodule Year 2/New Devices Lab/smart-shop/mongo_db-app
Already up to date.
Submodule path 'Year 2/New Devices Lab/smart-shop/final project': checked out 'eda28e13dc7cadeef8539fe0b2e3d6a2fe28cd0b'

PS D:\University> cd '.\Human-Computer Interaction\Project\HCI-Project\'
PS D:\University\Human-Computer Interaction\Project\HCI-Project> ls
PS D:\University\Human-Computer Interaction\Project\HCI-Project> cd '..\..\..\Semantics and Rewriting\PokeBattle-Project\'
PS D:\University\Semantics and Rewriting\PokeBattle-Project> ls
PS D:\University\Semantics and Rewriting\PokeBattle-Project> cd ../../
PS D:\University> cat .gitmodules
[submodule "smart-closet"]
        path = smart-closet
        url = ../smart-closet/
[submodule "Year 2/New Devices Lab/smart-closet"]
        path = Year 2/New Devices Lab/smart-closet
        url = ../smart-closet
[submodule "Year 2/New Devices Lab/smart-shop/final project"]
        path = Year 2/New Devices Lab/smart-shop/final project
        url = ../Smart-Shop-Project
[submodule "Year 2/New Devices Lab/smart-shop/login system"]
        path = Year 2/New Devices Lab/smart-shop/login system
        url = ../Basic-Node.js-Login-System/
[submodule "Year 2/New Devices Lab/smart-shop/mongo_db-app"]
        path = Year 2/New Devices Lab/smart-shop/mongo_db-app
        url = ../Mybrary/
[submodule "Semantics and Rewriting/PokeBattle-Project"]
        path = Semantics and Rewriting/PokeBattle-Project
        url = https://github.com/DragosSpiridon/PokeBattle-Project.git
[submodule "Human-Computer Interaction/Project/HCI-Project"]
        path = Human-Computer Interaction/Project/HCI-Project
        url = https://github.com/DragosSpiridon/HCI-Project.git

您还可以看到,子模块在

.gitmodules
文件中定义。知道发生了什么以及如何解决它吗?

git git-submodules
1个回答
0
投票

Peter Krebs 提供的链接包含了我需要的答案。更具体地说,我必须使用

git submodule update --init --recursive
。我不知道克隆时子模块也必须初始化。

注意:该命令只提取了第一次提交(我认为),之后我还必须在子模块目录中做另一个

git pull origin main

© www.soinside.com 2019 - 2024. All rights reserved.