git - 将现有的 git 存储库转换为父项目的子模块

标签 git shell

我有几个未版本控制的项目,这些项目又包含大量插件,其中一些是 git 克隆。我现在想将父项目转换为 git repo,最好不必遍历所有插件,识别哪些是 git repos,并手动将它们转换为父项目的子模块(当然,这是期望的结果) .

有没有简单的方法可以做到这一点?

最佳答案

您可以使用简短的 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

关于git - 将现有的 git 存储库转换为父项目的子模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12871494/

相关文章:

git - 如何将(未推送的)提交从一个分支移动到另一个分支

linux - 如何在远程主机上运行 bash function()?在Ubuntu中

macos - Automator 中的变量不起作用?

linux - 查找文件中出现的单词的所有实例

bash - 为什么正确的 shell 脚本会给出包装/截断/损坏的错误消息?

git - github桌面上的小红箭头和无标志是什么?

python - 具有多个分支的 github 存储库的唯一 git url?

git - 错误 : Workspace has a . git 存储库,但它似乎已损坏

如果远程文件夹包含空格,则 Git pull

linux - 从后台进程读取命名管道