Git will not init/sync/update new submodules

后端 未结 21 1983
野趣味
野趣味 2020-12-12 13:11

Here\'s part of the contents of my .gitmodules file:

[submodule \"src/static_management\"]
        path = src/static_management
        url = gi         


        
相关标签:
21条回答
  • 2020-12-12 14:02
    • Remove the submodule from your .git/config
    • Run git submodule init command
    • Go to your submodule directory and run git pull origin master

    It should works now

    0 讨论(0)
  • 2020-12-12 14:08

    There seems to be a lot of confusion here (also) in the answers.

    git submodule init is not intended to magically generate stuff in .git/config (from .gitmodules). It is intended to set up something in an entirely empty subdirectory after cloning the parent project, or pulling a commit that adds a previously non-existing submodule.

    In other words, you follow a git clone of a project that has submodules (which you will know by the fact that the clone checked out a .gitmodules file) by a git submodule update --init --recursive.

    You do not follow git submodule add ... with a git submodule init (or git submodule update --init), that isn't supposed to work. In fact, the add will already update the appropriate .git/config if things work.

    EDIT

    If a previously non-existing git submodule was added by someone else, and you do a git pull of that commit, then the directory of that submodule will be entirely empty (when you execute git submodule status the new submodule's hash should be visible but will have a - in front of it.) In this case you need to follow your git pull also with a git submodule update --init (plus --recursive when it's a submodule inside a submodule) in order to get the new, previously non-existing, submodule checked out; just like after an initial clone of a project with submodules (where obviously you didn't have those submodules before either).

    0 讨论(0)
  • 2020-12-12 14:08

    I had the same problem.

    .gitmodules had the submodule, but after a git submodule init command it wasn't in .git/config.

    Turns out the developer who added the submodule also added the submodule directory to the .gitignore file. That doesn't work.

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