Update Git submodule to latest commit on origin

后端 未结 14 1488
清歌不尽
清歌不尽 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:21

    The git submodule update command actually tells Git that you want your submodules to each check out the commit already specified in the index of the superproject. If you want to update your submodules to the latest commit available from their remote, you will need to do this directly in the submodules.

    So in summary:

    # Get the submodule initially
    git submodule add ssh://bla submodule_dir
    git submodule init
    
    # Time passes, submodule upstream is updated
    # and you now want to update
    
    # Change to the submodule directory
    cd submodule_dir
    
    # Checkout desired branch
    git checkout master
    
    # Update
    git pull
    
    # Get back to your project root
    cd ..
    
    # Now the submodules are in the state you want, so
    git commit -am "Pulled down update to submodule_dir"
    

    Or, if you're a busy person:

    git submodule foreach git pull origin master
    

提交回复
热议问题