git clone --recursive没有拉出最新的子模块

时间:2014-03-14 03:23:18

标签: git github git-submodules

由于某些原因,git命令git clone --recursive git@github.com:foo/bar.git没有从中获取最新信息 子模块。

对于子模块“sub”,它将返回较旧的提交:

$ cd other/sub/
$ git log | head -1
commit 57d0df7269949ef6d5347c5a4556fde7eafef16d

$  grep -r 57d0df7269949ef6d5347c5a4556fde7eafef16d .git/*
.git/modules/other/sub/HEAD:57d0df7269949ef6d5347c5a4556fde7eafef16d
.git/modules/other/sub/logs/HEAD:b0e43d8acf9fc38257b20ab7317b2b86110e8f72 57d0df7269949ef6d5347c5a4556fde7eafef16d Me
<me@hello.com> 1394764688 +0530     checkout: moving from master to 57d0df7269949ef6d5347c5a4556fde7eafef16d

知道为什么会这样吗?

How do I git clone --recursive and checkout master on all submodules in a single line?的一个答案表明我可能已将子模块固定到特定的sha,作者说这是正确的方法。在我的情况下,当我进行克隆时,我希望获得最新的,包括我的主仓库和它所引用的所有子模块。

如何确认子模块是否固定到sha 57d0df7269949ef6d5347c5a4556fde7eafef16d?如何删除它?

感谢。

1 个答案:

答案 0 :(得分:1)

git子模块总是固定到特定的提交 - 这就是子模块的工作原理 - 并且提交记录在父存储库中。这是为了确保一定程度的理智 - 如果多人克隆父存储库,即使子模块存储库中还有其他提交,它们也将获得相同版本的子模块。

如果要更新子模块提交,则需要先更新子模块:

cd submodule
git checkout master
git pull

然后在父存储库中记录新提交:

cd ..
git commit -m 'updated submodule' submodule

如果你想查看固定子模块的提交,只需运行git submodule,它将返回如下输出:

773d95e1dce80acea254465e896394a2eb158336 _posts (heads/posts)
94a6903384ca271b7e6ff74443ac2eddaf1d1da4 assets (heads/assets)

第一个字段是提交ID。你也可以用git ls-tree看到这个;对于存储库顶层的子模块:

git ls-tree master: | grep <directory_name>

对于不在顶层的子模块:

git ls-tree master:path/to/parent | grep <directory_name>

这应显示与git submodule相同的信息。

相关问题