2014-03-14 64 views
1

由于某种原因,git命令git clone --recursive [email protected]:foo/bar.git并未从 子模块中取得最新版本。git clone - 递归不拉最新的子模块

对于子模块“子”,它会回到旧的提交:

$ 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 
<[email protected]> 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

一个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:path/to/parent | grep <directory_name> 

这应该表现出相同的信息git submodule