将多个Git项目合并,保持历史记录
#!/bin/bash
shopt -s extglob
declare -a arr=("git@git.aaa.com:bbb/aaaaaFunction.git Function"
"git@git.aaa.com:bbb/aaaaaLogic.git Logic"
"git@git.aaa.com:bbb/aaaaaServices.git Services"
"git@git.aaa.com:bbb/aaaaaSolution.git Solution"
"git@git.aaa.com:bbb/aaaaaWebSites.git WebSites")
mkdir new_repo && cd new_repo
git init
for repo in "${arr[@]}"; do
IFS=' ' read -ra ADDR <<< "$repo"
git_url=${ADDR[0]}
subfolder=${ADDR[1]}
git clone $git_url temp_clone
cd temp_clone
git checkout master
git pull
git checkout -b prepare_monorepo
mkdir -p $subfolder
shopt -s extglob
git mv -k !(.$subfolder) $subfolder
shopt -u extglob
git rm -f --ignore-unmatch .gitattributes
git rm -f --ignore-unmatch .gitignore
git rm -f --ignore-unmatch .editorconfig
git commit -m "Preparing for monorepo merge"
cd ../
git remote add -f $subfolder temp_clone
git merge -m "Integrating $subfolder" $subfolder/prepare_monorepo --allow-unrelated-histories
git remote rm $subfolder
rm -rf temp_clone
done
git push
shopt -u extglob
标签:arr,git,aaa,多个,项目,合并,bbb,repo,com
From: https://www.cnblogs.com/zbw911/p/17451388.html