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

前端 未结 7 1136
感动是毒
感动是毒 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:31

    Use git ls-tree HEAD in the "superproject" folder to see what commit your submodule was originally at. Then change into the submodule directory and use git log --oneline --decorate to see what branch the original commit is on. Finally, git checkout original-commit-branch.

    Using some test directories I set up, here's what the commands might look like:

    $ git --version
    git version 1.7.4.1
    $ git status
    # On branch master
    # Changes not staged for commit:
    #   (use "git add <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   modified:   sm2 (new commits)
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    $ git ls-tree HEAD
    100644 blob 76813a07ae558db274cefc6d903ec24323fdeb0d    .gitmodules
    100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391    main
    160000 commit 7c5889497938cd5699a9234a98ee93947e52b1ed  sm1
    160000 commit f68bed61cba6f94cef57554f2cf46a45a4a0d337  sm2
    $ cd sm2
    $ git log --oneline --decorate
    5b8d48f (HEAD, foo1) foo1.1
    f68bed6 (origin/master, origin/HEAD, master) Initial commit.
    $ git checkout master
    Switched to branch 'master'
    $ cd ..
    $ git status
    # On branch master
    nothing to commit (working directory clean)
    

    The "superproject" shows the sm2 submodule at commit f68bed6 but sm2 has it's HEAD at 5b8d48f. The submodule commit f68bed6 has three branches on it that may be used for checkout in the submodule directory.

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