How to make submodule with detached HEAD to be attached to actual HEAD?

前端 未结 1 841
日久生厌
日久生厌 2020-12-13 14:28

When I add a Git submodule to a Git repository like this,

git submodule add ssh://server/proj1/ proj1
git submodule init
git submodule update
相关标签:
1条回答
  • 2020-12-13 14:48

    Update March 2013

    Git 1.8.2 added the possibility to track branches.

    "git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).

    # add submodule to track master branch
    git submodule add -b master [URL to Git repo];
    
    # update your submodule
    git submodule update --remote 
    

    See also the Vogella's tutorial on submodules.


    Original answer (December 2011)

    added submodule will be in detached HEAD mode

    Yes, a submodule is about referencing a specific commit, and not a branch.
    So:

    • If you checkout a commit SHA1 (or a tag), you are in a detached HEAD mode.
    • If you checkout a branch (like you did with master branch of the submodule), you can create other commits on top of that branch (but you will have to go back to the parent repo in order to commit said parent as well, for you need to record the new submodule commit you created)

    See "True nature of submodules" for more.

    If you always wanted the latest commit of another repo, the simplest way would be to merge them together (for instance with subtree merging).
    See "Merge 2 same repository GIT" for the details and references.

    0 讨论(0)
提交回复
热议问题