Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

Git submodule updating - HEAD doesn't match up to git log

I'm having trouble getting git's submodules to update properly when I pull a repository and the submodule's commit has changed. First off, I believe this question is different from this question because that question is concerned with staying up to date with a particular branch. I don't want the latest commit on a branch, I want the commit specified in the parent repository.

Here's my scenario:

Git repo A has repo B as a submodule. Repo A lists submodule B as being on commit abc.

Then, inside repo A, I do a git pull and receive a new commit for repo A. This new commit states that submodule B should now be on commit def. I run a git submodule update just to make sure everything is up to date.

Now here's where the problem arises.

I cd into submodule B and run git status. It reports HEAD detached at abc. Hmm, that's not right, it should be on def. But here's the confusing part - I run git log and the very first commit it lists is def, preceded by abc! How can that be? Shouldn't git log always start with HEAD? And if it knows about the new commit, why hasn't the working copy updated to reflect that?

Even after getting the submodule in the state described above, I can't figure out what git submodule ... command, if any, would move the B's head to be at bcd. The only fix I found was to cd into B and manually run git checkout bcd.

Help, please! I want a git pull in repo A to update submodule B to the commit has as indicated by A.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...