当前位置: 首页 > news >正文

架构优化——submodule转为subtree

文章目录

  • 背景
  • subtree优势
  • submodule切换到subtree脚本
  • subtree使用
    • 切开发分支
    • 推送代码
    • 同步代码

背景

submodule过多,目前20个submodule需要切出20个分支,查看提交记录、切分支等使用起来麻烦。

团队深受困扰!

subtree优势

  1. 继承submodule的优点,基础功能仓库,可被其他多个仓库同时使用
  2. 开发时,不需要再切n个分支,也不需要提到不同仓库,只需要往主仓库推送即可,一个仓库一个分支,搞定日常开发,让开发工作更愉快
  3. 代码合并时,不需要再合那么多子仓库

submodule切换到subtree脚本

可以一键切换,但是要注意m_branch的更改,更改为子模块你想追踪的分支名

#!/bin/bash
# set -e
m_branch="release/3_5_6_2"
cat .gitmodules | while read i; doif [[ $i == \[submodule* ]]; thenecho converting $iread impath=$(echo $i | grep -E "(\S+)$" -o)echo path: $mpathread imurl=$(echo $i | cut -d= -f2 | xargs)echo url: $murlmname=$(basename $mpath)echo name: $mname# 先获取 commit,必须在 git rm 之前mcommit=$(git ls-tree HEAD "$mpath" | awk '{print $3}')echo commit: $mcommitgit submodule deinit -f "$mpath"echo "11"git add .git commit -m "#40664 Stage .gitmodules changes before removing submodule"git rm -r --cached "$mpath"echo "22"rm -rf "$mpath"echo "33"git config -f .gitmodules --remove-section "submodule.$mpath" || trueecho "44"git config --remove-section "submodule.$mpath" || trueecho "55"git commit -m "#40664 Removed $mpath submodule at commit $mcommit"echo "66"if ! git remote get-url "$mname" &>/dev/null; thengit remote add "$mname" "$murl"fiecho "77"# git fetch "$mname"# 用 commit 创建临时分支并用它 add subtree# git branch -f "_$mname" "$mcommit"echo "88"git add .git commit -m "#40664 Save changes before subtree add"echo "mpath:$mpath murl:$murl  m_branch:${m_branch} "git subtree add --prefix="$mpath" "$murl" "${m_branch}"echo "99"# git branch -D "_$mname"echo "10"git commit -m "#40664 Converted $mpath submodule to subtree"echo "11"git push origin "${m_branch}"echofi
donegit rm -f .gitmodules
git commit -m "#40664 Removed .gitmodules after converting submodules"

subtree使用

接入subtree后,日常开发提交代码,切分支等,都只对主仓库进行操作,日常使用起来,就只是主仓库。

更新的内容也只在主仓库生效(默认子仓库不会同步更新)

如需单独更新子模块仓库,需要用特殊的命令

切开发分支

git checkout -b  feature/3553_xzx_subtree
git push origin  feature/3553_xzx_subtree
# 以上即可开始开发

推送代码

git add 修改文件
git commit -m "修改内容"
git push origin  feature/3553_xzx_subtree
# 以上即可推送修改到云端(只会更新quicktron仓库),然后直接打包即可,会把提交的修改带上

如果需要单独推送子模块仓库(只开发quicktron,是不需要做这一步的

例如params_api未来可能被quicktron以及算法那边的仓库共同使用,我们在params_api修复了bug,则需要推送到子模块仓库中去,让算法那边也可同步到我们的修改,则使用以下命令:

git subtree push --prefix=src/nav_process ssh://git@gitlab.flashhold.com:10022/hardware/upper_computer/basic/nav_process.git feature/3553_xzx_subtree

同步代码

git pull origin release/3_5_5_3
git push origin  feature/3553_xzx_subtree
# 以上即可同步最新修改到本地,并且推送到quicktron仓库

如果需要单独更新某个子模块(只开发quicktron,是不需要做这一步的

例如params_api被算法那边修复了bug,并且已经推送到对应子仓库了,那我们需要同步最新修改到qucktron

则使用以下命令:

git subtree pull --prefix=src/params_api ssh://git@gitlab.flashhold.com:10022/hardware/upper_computer/basic/nav_process.git release/3_5_5_3
git push origin  feature/3553_xzx_subtree

在submodule初步切为subtree这段时间,可能有原先是submodule形式的提交,在nav_process子仓库上的修改,需要同步到subtree形式的主线上,则也是使用以上指令。

相关文章:

  • 【生活】ECMO原理、作用、费用及使用方法
  • Go语言中的 函数、闭包、defer、错误处理
  • SKUA-GOCAD入门教程-第八节 线的创建与编辑5
  • 黄金价格触及3400美元临界点:AI量化模型揭示美元强势的“逆周期”压制力与零售数据爆冷信号
  • React+Taro创建小程序
  • Mac m1 通过docker镜像安装kafka
  • Smart Input Pro IDEA 插件推荐
  • Redis(2)——AOF持久化
  • 不依赖rerank 模型排序通过使用 PostgreSQL 中的 pgvector 与 tsearch2 函数进行混合搜索提高召回率
  • 机器学习重构光子学设计范式:从智能器件到前沿系统
  • 腾讯云TCCP认证考试报名 - TDSQL数据库交付运维高级工程师(PostgreSQL版)
  • 【Linux】基于单例模式的线程池设计
  • window11中开启ubuntu22.04子系统
  • Process simulate机器人操作工艺仿真
  • VGG-19(Visual Geometry Group)模型
  • ubuntu使用tftp传输文件
  • Ubuntu 使用kubeadm部署k8s系统组件反复重启的问题
  • ubuntu2404 Server扩展PV
  • 剑指offer32_二叉搜索树的后序遍历序列
  • OpenCV根据模板图像寻找环境中的目标
  • wordpress判断子分类/南宁seo推广公司
  • 计算机网站建设论文/太原seo排名公司
  • 哪个博客可以做单页网站/百度怎么搜索网址打开网页
  • 开封市住房和城乡建设网站/360网站推广怎么做
  • 用macbook做网站开发吗/seo教程自学网
  • 甘肃省路桥建设集团网站/郑州seo哪家专业