For some reason the git command git clone --recursive git@github.com:foo/bar.git is not pulling the latest from the submodules.

For the submodule "sub", it is going back to an older commit:

$ 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

Any idea why this is happening?

One answer at How do I git clone --recursive and checkout master on all submodules in a single line? suggests I might have pinned the submodule to particular sha, which the author says is the correct way to do. In my case, I want to get the latest, both in my main repo and all the submodules it refers to, when I do the clone.

How do I confirm if the submodule is pinned to the sha 57d0df7269949ef6d5347c5a4556fde7eafef16d? How do I remove it?

thanks.

有帮助吗?

解决方案

A git submodule is always pinned to a particular commit -- this is just how submodules work -- and that commit is recorded in the parent repository. This is to ensure some level of sanity -- if multiple people clone the parent repository, they will all get the same version of the submodule even if there have been additional commits in the submodule repository.

If you want to update the submodule commit, you need to first update the submodule:

cd submodule
git checkout master
git pull

And then record the new commit in the parent repository:

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

If you want to see the commit to which a submodule is pinned, just run git submodule, which will return output like this:

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

The first field is the commit id. You can also see this with git ls-tree; for a submodule in the top level of your repository:

git ls-tree master: | grep <directory_name>

For a submodule not in the top level:

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

This should show the same information as git submodule.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top