How to revert a Git Submodule pointer to the commit stored in the containing repository?

前端 未结 7 1306
感动是毒
感动是毒 2021-01-29 22:44

I have a git submodule in my main git repo. As I understand it, the main repo stores a SHA value (somewhere...), pointing to the specific commit of the submodule that it is \"li

7条回答
  •  忘了有多久
    2021-01-29 23:26

    To change the commit that a submodule points to, you need to checkout that version in the submodule, then go back to the containing repo, add and commit that change.

    Or, if you want the submodule to be on the version the top repo points to, do git submodule update --recursive. Add --init if you've just cloned.

    Also, git submodule without a submodule command will show you the commit you are pointing to. There will be a - or a + in front of the commit if it's not in sync.

    If you look at a tree with a submodule in it, you can see that the submodule is marked as a commit as opposed to the rest that are blobs or trees.

    to see what a particular commit points wrt to submodules you can:

    git ls-tree  Submodule/path
    

    you can then see the commit or anything else if you like by passing that into log, etc (the git-dir option at the git command level allows you to skip having to cd down to the submodule):

    git --git-dir=Submodule/path log -1 $()
    

提交回复
热议问题