如何优雅地抽离 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 等一起推)
相关推荐
wflynn3 小时前
GitHub 今日推荐|rust-anything:录制真实输入输出,渐进式重写热点函数到 Rust
rust·开源·github·cli·claude-code·agent-skills
风笙97818 小时前
[Rust] String 与 &str 详解
rust
风笙97821 小时前
[Rust]复合类型
rust
风笙97821 小时前
[Rust] 所有权与引用
rust
Kapaseker1 天前
最近用 Rust 写工具,我发现这 7 个库是真好用
rust
SomeOtherTime2 天前
第 11 讲(大结局):编译期元编程与零拷贝架构——卫生声明宏(macro_rules!)、过程宏 AST 手术刀与 Serde 零反射序列化的终极合龙
rust
SomeOtherTime2 天前
番外篇(第 12 讲):走向工业界深水区——从物理定律看 Rust 在真实工程中的“降维打击”与“阿喀琉斯之踵”
开发语言·rust
Kapaseker2 天前
Rust 桌面开发到底怎么选?先看这篇文章!
rust
奶油话梅糖2 天前
容器启停 2.5 毫秒:11 天 1,700 Star 的 Kiri,用一个 900 KB 的 PID 1 干掉了 runc 和 dockerd
前端·人工智能·rust
wflynn3 天前
GitHub 今日推荐|kiri:clone3 系统调用直达容器,2.5 毫秒启动无 runc 中间层
docker·rust·kubernetes·开源·github·containers