如何优雅地抽离 Rust 子工程:以 rumqttd 为例

下载工具git-filter-repo

python 复制代码
# macOS
brew install git-filter-repo
# Debian/Ubuntu
sudo apt-get install git-filter-repo
# or via pip
pip install git-filter-repo

克隆上游裸仓库

bash 复制代码
git clone --mirror https://gitlab.com/rumqtt/rumqttd.git rumqttd.git
cd rumqttd.git          # 注意:裸仓库,无工作区

裸仓库能一次带下所有分支 / tag,且速度快。


过滤:只保留子目录并"脱壳"(只保留需要的目录,脱壳)

css 复制代码
# ① 仅保留 rumqttd/src 和 Cargo*,其它全部丢弃
# ② 把 rumqttd/ 这一层目录去掉(即 rumqttd/src/foo.rs 变成 src/foo.rs)
git filter-repo \
  --path rumqttd/src \
  --path rumqttd/Cargo.toml \
  --path rumqttd/Cargo.lock \
  --path-rename rumqttd/:

从刚才裁剪后的裸仓库再克隆出一个"普通仓库"

你当前在 work/ 目录,而不是刚才的 rumqttd.git

bash 复制代码
 
git clone rumqtt.git rumqttd-lite          # 目录名随意
cd rumqttd-lite

看看有哪些分支,HEAD 通常已经指向 main

css 复制代码
git branch -a

如果 HEAD 不是 main,可手动

css 复制代码
git checkout main

添加新的远程(GitHub / GitLab 皆可)

bash 复制代码
# 如果要推到内部 GitLab,就把 URL 换成对应地址
git remote add origin git@github.com:someone/rumqttd.git

一次性推送所有分支 + tag

perl 复制代码
git push --all origin     # 推送分支
git push --tags origin    # 推送标签
# 或者直接   git push --mirror origin   (连同 refs/notes 等一起推)
相关推荐
星释2 小时前
Rust 练习册 67:自定义集合与数据结构实现
数据结构·算法·rust
LengineerC8 小时前
Rust仿node事件总线的简单实现
设计模式·rust
r***d8659 小时前
Rust宏编程指南
开发语言·后端·rust
星释9 小时前
Rust 练习册 80:Grains与位运算
大数据·算法·rust
wei_shuo11 小时前
zoxide 开源鸿蒙 PC 生态适配实战:Rust 交叉编译与 HNP 打包完整指南
rust·开源鸿蒙·zoxide
大鱼七成饱1 天前
Rust进阶必备:thiserror用法全面解析
rust
Amos_Web1 天前
Rust实战(四):数据持久化、告警配置与Web API —— 构建监控系统的功能闭环
前端·后端·rust
联系QQ:4877392781 天前
Bayes-CNN-LSTM、Bayes-CNN-BiLSTM、Bayes-CNN-GRU、B...
rust
空白诗1 天前
tokei 在鸿蒙PC上的构建与适配
后端·华为·rust·harmonyos
疏狂难除1 天前
尝试rust与python的混合编程(一)
开发语言·后端·python·rust