Restore git submodules from .gitmodules

前端 未结 7 613
粉色の甜心
粉色の甜心 2020-12-02 04:47

I have a folder, which was a git repo. It contains some files and .gitmodules file. Now, when I do git init and then git submodule init, the latter

7条回答
  •  广开言路
    2020-12-02 05:37

    git submodule init only considers submodules that already are in the index (i.e. "staged") for initialization. I would write a short script that parses .gitmodules, and for each url and path pair runs:

    git submodule add  
    

    For example, you could use the following script:

    #!/bin/sh
    
    set -e
    
    git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
        while read path_key path
        do
            url_key=$(echo $path_key | sed 's/\.path/.url/')
            url=$(git config -f .gitmodules --get "$url_key")
            git submodule add $url $path
        done
    

    This is based on how the git-submodule.sh script itself parses the .gitmodules file.

提交回复
热议问题