我有几个未版本控制的项目,这些项目又包含大量插件,其中一些是 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/