简体   繁体   English

将现有的git repos转换为父项目的子模块

[英]Turn existing git repos into submodules of parent project

I have several, unversioned projects which in turn contain a large number of plugins, some of which are git clones. 我有几个无版本的项目,而这些项目又包含大量的插件,其中一些是git克隆。 I now want to turn the parent project into a git repo, preferably without having to go through all the plugins, identifying which are git repos, and manually convert them to submodules of the parent project (which is, of course, the desired outcome). 我现在想把父项目变成一个git repo,最好不必遍历所有的插件,识别哪些是git repos,并手动将它们转换为父项目的子模块(当然,这是期望的结果) 。

Is there an easy way to do this? 是否有捷径可寻?

You could do this with a short shell script: 您可以使用简短的shell脚本执行此操作:

#!/bin/sh

for d in plugins/*
do
    if [ -e "$d/.git" ]
    then
        # Unstage the gitlink, so we can then add it back as a submodule:
        git rm --cached "$d"
        # Guess that the URL for origin is a reasonable one to use:
        URL="$(cd "$d" && git config remote.origin.url)"
        # Add the git repository back as a submodule:
        git submodule add "$URL" "$d"
    fi
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM