git submodule checks out the same commit

前端 未结 4 1957
一整个雨季
一整个雨季 2021-01-15 05:34

After I git submodule update it always checks out the same commit. for example 34561.

I do git checkout master for submodule a

4条回答
  •  独厮守ぢ
    2021-01-15 05:43

    I mean why it decided to point to that commit and not another?

    Because a submodule always records a fixed SHA1 commit in the parent repo as a gitlink (a special entry in the index).
    That is why a submodule is always restored as a detached HEAD branch

    You can configure a submodule to follow a branch

    cd /path/to/your/parent/repo
    git config -f .gitmodules submodule..branch 
    

    The submodule would still be restored to a fixed commit, but can then be updated with:

    git submodule update --remote
    

    Make sure to add and commit the new gitlink in the parent repo (since updating a submodule to the latest of a branch would change its SHA1, recorded in the parent repo as a gitlink).
    If you don't, you will find back your submodule to its previous state at then next git submodule update --init.

    See more at "Git submodules: Specify a branch/tag".

提交回复
热议问题