Git will not init/sync/update new submodules

后端 未结 21 1981
野趣味
野趣味 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条回答
  • I had the same problem but none of the solutions above helped. The entries in the .gitmodules and in .git/config were right but the command git submodules update --init --recursive was doing nothing. I also removed the submodule directory and did run git submodules update --init --recursive and got the submodule directory back but with exactly the same commit as before.

    I found the answer on this page. The command is:git submodule update --remote

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

    Deleting submodule dir and its contents ("external/pyfacebook" folder) if it exists before git submodule add ... might fix problems.

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

    I had the same problem today and figured out that because I typed git submodule init then I had those line in my .git/config:

    [submodule]
       active = .
    

    I removed that and typed:

    git submodule update --init --remote
    

    And everything was back to normal, my submodule updated in its subdirectory as usual.

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

    The problem for me is that the repo's previous developer had committed the submodules/thing folder as just a regular folder, meaning when I tried to run git submodule add ..., it would fail with: 'submodules/thing' already exists in the index, yet trying to update the submodule would also fail because it saw that the path did not contain a submodule.

    To fix, I had to delete the submodules/thing folder, commit the deletion, then run the git submodule add command to add it back correctly:

    git submodule add --force --name thing https://github.com/person/thing.git submodules/thing
    
    0 讨论(0)
  • 2020-12-12 13:52

    Sort of magically, but today I ran git submodule init followed by git submodule sync followed by git submodule update and it started pulling my submodules... Magic? Perhaps! This is truly one of the most annoying experiences with Git…

    Scratch that. I actually got it working by doing git submodule update --init --recursive. Hope this helps.

    PS: Make sure you are in the root git directory, not the submodule's.

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

    This means the submodules haven’t been set up correctly and a git submodule add command will have to be executed.

    IF SUBMODULES WERE ADDED CORRECTLY

    To give some background, when a repo with submodules has been set up correctly someone has already performed a git submodule add command, which does the following things:

    1. create a folder for the submodule to reside in if it doesn’t already exist
    2. clone the project as a submodule
    3. set the submodule parameters in the shareable .gitmodules file
    4. set the submodule parameters in your private .git/config file
    5. create a .git folder for the submodule in your superproject’s private .git/modules folder
    6. and also: record in your superproject’s index for each submodule in which folder it will reside, and in what state it should be (the hash commit code of the submodule.)

    Point 3 and 6 are relevant when you clone the superproject, and point 6 indicates whether a git submodule add has been performed correctly and was committed. You can check point 6 by seeing whether the folders in which the submodules should reside are already there and empty (Note: this does not require a .keep or .gitignore mechanism to be in place, since this is part of a Git mechanism.) After cloning the superproject you can also perform a git submodule to see which submodules are expected.

    You can then proceed by doing:

    • git submodule

      will show the submodules present in the tree and their corresponding commit hash code, can serve as an initial check to see which submodules are expected

    • git submodule init

      copies the submodules parameters from the repo’s .gitmodules file to your private .git/config file (point 4)

    • git submodule update

      clones the submodules to a commit determined by the superproject and creates the submodules' .git folders under your superproject's .git/modules/ folder (points 2 and 5)

    • git submodule update --remote

      same as update but sets the submodule to the latest commit on the branch available by the remote repo, similar as going in each submodule’s folder afterwards and do a git pull

    • or: git submodule update --init --remote

      which is all of the above combined.

    Alternatively, when the repo is set up correctly, you can also do a git clone with the --recursive flag to include the submodules with the init and update performed on them automatically.

    IF SUBMODULES WERE NOT ADDED CORRECTLY

    But if the submodules are not committed correctly, and the submodules and their corresponding folders are not already recorded in the index, then first every submodule in the .gitmodules file needs to be individually added via git submodule add before one can proceed.

    • Note: as mentioned here, Git does not currently have a command to do this at once for multiple submodules present in a .gitmodules file.
    0 讨论(0)
提交回复
热议问题