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
310 views
in Technique[技术] by (71.8m points)

git submodule init not pulling latest commit

I have a git repo with a git submodule inside of it. The submodule is hosted on bitbucket. I want to update my local copy of the submodule to its latest commit. I tired "git submodule update" however that is not doing anything. So I tried deleting the submodule folder and then doing "git submodule init" However it simply pulls the initial submodule commit, not the latest.

How can I get my local submodule to update to the latest commit?

question from:https://stackoverflow.com/questions/13844996/git-submodule-init-not-pulling-latest-commit

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

1 Answer

0 votes
by (71.8m points)

Git is doing exactly what it's supposed to be doing. git submodule update will set your submodule to what the current commit in the parent repo specifies the submodule should be at. This way you can checkout another branch, older commit or tag, then run git submodule update and the submodule will be set to what that reference expects so your entire solution will have it's dependencies satisfied.

What you need to do is:

cd mysubmoduledir
git fetch
git checkout master # or any other branch that you need the latest of
git merge origin/master
cd -  # go back to the top repo
git status # should show that your submodule changed
git add mysubmoduledir
git commit -m "Updated my solution to use latest sub project."

a shorter version is:

cd mysubmoduledir
git pull # assumes you are already on the branch you need to be on
cd -
git commit -am "Updated submodule" # assumes you had no other modified files

The word "update" is not the best for this submodule command. It really means "point the submodule to the commit that the parent repo's commit expects".

Updating a submodule to a different commit (doesn't have to be the latest) requires you to cd into that directory, manipulate it like a regular git repo so the current commit is what you want, then go back out and commit this change on the top level repo.


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

...