Update Git submodule to latest commit on origin

后端 未结 14 1489
清歌不尽
清歌不尽 2020-11-27 09:02

I have a project with a Git submodule. It is from an ssh://... URL, and is on commit A. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit

14条回答
  •  渐次进展
    2020-11-27 09:16

    Your main project points to a particular commit that the submodule should be at. git submodule update tries to check out that commit in each submodule that has been initialized. The submodule is really an independent repository - just creating a new commit in the submodule and pushing that isn't enough. You also need to explicitly add the new version of the submodule in the main project.

    So, in your case, you should find the right commit in the submodule - let's assume that's the tip of master:

    cd mod
    git checkout master
    git pull origin master
    

    Now go back to the main project, stage the submodule and commit that:

    cd ..
    git add mod
    git commit -m "Updating the submodule 'mod' to the latest version"
    

    Now push your new version of the main project:

    git push origin master
    

    From this point on, if anyone else updates their main project, then git submodule update for them will update the submodule, assuming it's been initialized.

提交回复
热议问题