如何优雅地抽离 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 等一起推)
相关推荐
古城小栈11 分钟前
Rust 已经自举,却仍需GNU与MSVC工具链的缘由
开发语言·rust
古城小栈10 小时前
Rust 迭代器产出的引用层数——分水岭
开发语言·rust
peterfei15 小时前
IfAI v0.2.8 技术深度解析:从"工具"到"平台"的架构演进
rust·ai编程
栈与堆18 小时前
LeetCode-1-两数之和
java·数据结构·后端·python·算法·leetcode·rust
superman超哥19 小时前
双端迭代器(DoubleEndedIterator):Rust双向遍历的优雅实现
开发语言·后端·rust·双端迭代器·rust双向遍历
福大大架构师每日一题20 小时前
2026年1月TIOBE编程语言排行榜,Go语言排名第16,Rust语言排名13。C# 当选 2025 年度编程语言。
golang·rust·c#
superman超哥1 天前
精确大小迭代器(ExactSizeIterator):Rust性能优化的隐藏利器
开发语言·后端·rust·编程语言·rust性能优化·精确大小迭代器
superman超哥1 天前
惰性求值(Lazy Evaluation)机制:Rust 中的优雅与高效
开发语言·后端·rust·编程语言·lazy evaluation·rust惰性求值
古城小栈1 天前
Rust IO 操作 一文全解析
开发语言·rust
superman超哥1 天前
迭代器适配器(map、filter、fold等):Rust函数式编程的艺术
开发语言·rust·编程语言·rust map·rust filter·rust fold·rust函数式