Git will not init/sync/update new submodules

后端 未结 21 1980
野趣味
野趣味 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 13:43

    git version 2.7.4. This command updates local code git submodule update --init --force --remote

    0 讨论(0)
  • 2020-12-12 13:43

    Please check your submodules directory.

    If there is only a .git file in it, then delete it.

    Now execute git submodule update --remote --init

    0 讨论(0)
  • 2020-12-12 13:44

    I had this same problem - it turned out that the .gitmodules file was committed, but the actual submodule commit (i.e. the record of the submodule's commit ID) wasn't.

    Adding it manually seemed to do the trick - e.g.:

    git submodule add http://github.com/sciyoshi/pyfacebook.git external/pyfacebook
    

    (Even without removing anything from .git/config or .gitmodules.)

    Then commit it to record the ID properly.

    Adding some further comments to this working answer: If the git submodule init or git submodule update does'nt work, then as described above git submodule add url should do the trick. One can cross check this by

     git config --list
    

    and one should get an entry of the submodule you want to pull in the result of the git config --list command. If there is an entry of your submodule in the config result, then now the usual git submodule update --init should pull your submodule. To test this step, you can manually rename the submodule and then updating the submodule.

     mv yourmodulename yourmodulename-temp
     git submodule update --init
    

    To find out if you have local changes in the submodule, it can be seen via git status -u ( if you want to see changes in the submodule ) or git status --ignore-submodules ( if you dont want to see the changes in the submodule ).

    0 讨论(0)
  • 2020-12-12 13:44

    Had the same issue, when git ignored init and update commands, and does nothing.

    HOW TO FIX

    1. Your submodule folder should be committed into git repo
    2. It shouldn't be in .gitignore

    If that requirements met, it will work. Otherwise, all commands will execute without any messages and result.

    If you did all that, and it still doesn't work:

    1. Add submodule manually, e.g. git submodule add git@... path/to
    2. git submodule init
    3. git submodule update
    4. commit and push all files - .gitmodules and your module folder (note, that content of folder will not commit)
    5. drop your local git repo
    6. clone a new one
    7. ensure that .git/config doesn't have any submodules yet
    8. Now, git submodule init - and you will see a message that module registered
    9. git submodule update - will fetch module
    10. Now look at .git/config and you will find registered submodule
    0 讨论(0)
  • 2020-12-12 13:45

    According to the answer from Dave James Miller I can confirm that it worked for me. The important thing here was to commit the subprojects commit ID. Just to have the entry in .gitmodules was not enough.

    Here is an appropriate commit:

    https://github.com/dirkaholic/vagrant-php-dev-box/commit/d5f4c40bdbd80eefbb5ac6029823733f591435ae

    0 讨论(0)
  • 2020-12-12 13:48

    Just sharing what worked for me:

    git clone --recurse-submodules <repository path>
    

    This clones the remote repository already including the submodules. This means you won't need to run git submodule update or init after cloning.

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