在gitlab中将项目的现有模块更改为mono repo及其分支和提交历史

zfciruhq  于 2024-01-04  发布在  Git
关注(0)|答案(1)|浏览(164)

我有一个名为A的Git仓库,它有三个分支。它是一个多模块项目,由模块B、C、D、E和F组成,其中E和F是monorepo中的子模块。这些模块与主仓库A共享相同的分支。我想将模块C转换为monorepo,同时保留相同的分支和提交历史。
当前,我正在使用以下命令 checkout 项目。这将导致monorepo具有子模块E和F。将模块C转换为monorepo后,clone命令应给予子模块C。如何实现这一点?

git clone --recursive https://gitlab..../A.git

字符串

dwthyt8l

dwthyt8l1#

最后我找到了解决办法

git clone https://git..../A.git
cd A
for i in $(git branch -r | sed "s/.*origin\///"); do git branch -t $i origin/$i; done
git filter-branch --prune-empty --subdirectory-filter C -- --all
git filter-branch --prune-empty --tree-filter 'rm -rf C' -- --all
git remote -v
git remote set-url origin https://git.../C.git
git remote -v
git push -u origin --all

字符串
//对所有分支执行以下操作

git clone https://git..../A.git
cd A


删除文件夹c并添加子模块参考

gi add .
git commit -m "folder removed"
git push origin trunk 
git submodule add https://git..../C.git
cd C
git checkout trunk
git add .
git commit -m "new submodule ref added"
git push origin trunk

相关问题