Get hash of submodule at previous version of main repo without checking out

前端 未结 1 1280
野的像风
野的像风 2020-12-11 23:27

I have a repo which a submodule in it.

I can get the current hash of the submodule from the working directory easily:

cd submodule
git rev-list HEAD          


        
相关标签:
1条回答
  • 2020-12-12 00:09

    Use git rev-parse (which is also the correct tool for reading the value of HEAD):

    git rev-parse some_tag:submodule
    

    This reads the gitlink entry from the tree object to which some_tag can be resolved, using the supplied path. To see how it works, use:

    tree=$(git rev-parse some_tag^{tree})
    git ls-tree -r $tree
    

    (the -r option is only required if the submodule path is not at the top level of the repository). Note that the tree entry for the submodule is simply 160000 commit <hash> <path>: this is how the superproject knows which commit hash ID to use in the submodule.

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