Git子模块.拉入超级项目的新克隆

int*_*tar 85 git git-submodules

好.所以我以为我有这个舔...但现在....

我有一个项目,其中包括一个来自GitHub的小型库作为子模块.在该超级项目的原始版本中,子模块按预期工作.

但是,我只是克隆了超级项目,做了我认为应该做的事情:"git submodule init",得到子模块的目录,但它是空的.

如果我现在尝试做

git submodule update
Run Code Online (Sandbox Code Playgroud)

我明白了

fatal: Needed a single revision 
Unable to find current revision in submodule path 'external_libraries/BEACHhtml'
Run Code Online (Sandbox Code Playgroud)

如果我试试

git submodule foreach git pull
Run Code Online (Sandbox Code Playgroud)

我明白了

Entering 'external_libraries/BEACHhtml'
fatal: Where do you want to fetch from today?
Stopping at 'external_libraries/BEACHhtml'; script returned non-zero status.
Run Code Online (Sandbox Code Playgroud)

在我的.git/config中,我有这个:

[submodule "external_libraries/BEACHhtml"]
    url = git@github.com:interstar/BEACHhtml.git
Run Code Online (Sandbox Code Playgroud)

在我的.gitmodules中我有这个:

[submodule "external_libraries/BEACHhtml"]
path = external_libraries/BEACHhtml
url = git@github.com:interstar/BEACHhtml.git
Run Code Online (Sandbox Code Playgroud)

任何人都知道缺少什么?

Han*_* He 186

我和你有同样的问题.这是git中的一个错误:http://lists-archives.com/git/785138-git-submodule-update-is-not-fail-safe.html

简而言之,对于您的问题,请尝试:

# rm -rf external_libraries/BEACHhtml
# git submodule update
Run Code Online (Sandbox Code Playgroud)

以前的checkout文件夹似乎有问题,删除它,并再次更新解决问题.

  • 我不得不删除子模块worktree(`ext/blah`)和`GIT_DIR`下面的匹配文件夹(`.git/modules/ext/blah`). (30认同)
  • 2018年登记,git submodule更新仍然很糟糕. (10认同)
  • 在2016年,这个错误仍在继续:( (8认同)
  • 2017年入住,仍在场. (6认同)
  • 在我的特定情况下,`git submodule update`在我的CI服务器上保持失败,因为它希望有人接受RSA密钥(ci服务器通常使用https连接,这是子模块第一次在ssh连接中提取).希望它可以节省一个小时的头部刮伤! (2认同)

Lu5*_*u55 5

通过删除 2 个目录并重新获取子模块解决:

  1. 转到external_libraries/BEACHhtml并查看.git文件。它的内容应该是这样的gitdir: ../../.git/modules/external_libraries/BEACHhtml
  2. 删除external_libraries/BEACHhtml.git/modules/external_libraries/BEACHhtml目录。

从现在开始git submodule update运行没有错误。