Restore git submodules from .gitmodules

前端 未结 7 586
粉色の甜心
粉色の甜心 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:19

    Extending excellent @Mark Longair's answer to add submodule respecting branch and repo name.

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

提交回复
热议问题