如何优雅地抽离 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 等一起推)
相关推荐
wflynn4 小时前
GitHub 今日推荐|lightcraft:纯 Rust 重写的 RAW 照片开发工具
rust·开源·github·lightroom·art·photography
geovindu4 小时前
rust: Flyweight Pattern
开发语言·后端·设计模式·rust·享元模式·结构型模式
golang学习记1 天前
rust开发,选VS Code还是RustRover?
开发语言·后端·rust
滕州市燕猫虎计算机科技工作室个体工商户1 天前
《Rust程序设计》学习笔记二
rust·学习笔记
滕州市燕猫虎计算机科技工作室个体工商户1 天前
《Rust程序设计》学习笔记三
rust·学习笔记·rust程序设计
geovindu1 天前
rust: Facade Pattern
开发语言·后端·设计模式·rust·外观模式
福大大架构师每日一题1 天前
Rust 1.99.0发布:C 可变参数、裸函数、Cargo 配置、Rustdoc 性能与大量兼容性调整全解析
c语言·开发语言·rust
DongQiShanRen1 天前
裁决台账双向互校(下):台账哈希链、三向对账与最小落地
人工智能·深度学习·算法·目标跟踪·自然语言处理·rust·哈希算法
行者-全栈开发1 天前
华为云码道 CodeArts 实测:让 AI 用 Rust 写一个 Git 仓库健康度体检台「仓衡」
git·rust·tauri·桌面应用·ai 编程·华为云码道·codearts 代码智能体
miofly1 天前
GitHub 今日推荐|lightcraft:纯 Rust 重写的 RAW 照片开发工具
rust·开源·github