Git will not init/sync/update new submodules

后端 未结 21 2130
野趣味
野趣味 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
    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.

提交回复
热议问题