Rift:Git Worktrees 的更优替代方案

Hacker News Top 工具

摘要

Rift 是一个命令行工具,提供比 Git worktrees 更好的替代方案,通过写时复制快照在 Linux 的 btrfs 和 macOS 的 APFS 上实现快速创建工作区。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/06/01 10:41

anomalyco/rift

来源:https://github.com/anomalyco/rift

rift:git worktrees 的更优替代方案

  • 写时复制(节省空间)
  • 即时运行(10GB 文件夹耗时 < 0.1 秒)
  • 快速的 CLI
  • 可与 bun 或 node 以 FFI 库形式使用

目前支持 macOS 和 Linux+btrfs,后续将支持更多平台。

安装

npm install -g rift-snapshot
# 或
bun add -g rift-snapshot

发布归档可从 GitHub Releases 获取(https://github.com/anomalyco/rift/releases/latest)。

平台

平台后端行为
Linux x64可写 btrfs 快照rift init 将普通目录转换为 btrfs 子卷。
macOS arm64 / x64APFS clonefilerift init 注册源目录。
Windows x64包已发布,但工作区创建功能尚未实现。

CLI

初始化

cd ~/code/app
rift init

rift init 会选择当前目录上方的现有 Rift 根目录,若不存在 Rift 根目录则选择最近的 Git 根目录。使用 --here 可只初始化指定的目录。

在 Linux 上,首次初始化普通 btrfs 目录时,会通过 reflink 导入到一个新的 btrfs 子卷中,并将其替换到原路径。如果所选根目录已注册,则不进行转换。如果缺少 .rift 标记,rift init 会恢复该标记并完成所需的转换。

创建

rift create
rift create --name parser-fix
rift create --into /fast/rifts

rift create 向上搜索 .rift,复制该托管工作区,记录直接父级,并将新工作区路径打印到标准输出。

在 Linux 上,会创建可写 btrfs 快照。在 macOS 上,使用 APFS clonefile

如果工作区是 Git 仓库,新工作区将以分离的 HEAD 状态创建,并保留索引和工作树状态。

列出与祖先

rift list
rift ancestors

list 打印直接活跃的子工作区。ancestors 打印父工作区,最近的在前。

删除与垃圾回收

rift remove                         # 将当前创建的 rift 子树移入回收站
rift remove -f ~/code/app           # 取消注册源根目录
rift remove --children ~/code/app   # 移出子项至回收站,保留选定工作区
rift gc                             # 物理删除回收站中的内容,并清理缺失的条目

删除创建的 rift 会将其活跃子树移至相邻的 .trash 存储中。rift gc 会在之后删除该存储。

删除源根目录需要在 CLI 中使用 -f 参数。源目录保留在磁盘上,但其 .rift 标记会被移除。已注册的子项会被移入回收站,缺失的子项会从注册表中移除。

Shell 集成

eval "$(rift shell-init zsh)" # 或 bash

init 转换、create 或删除当前创建的 rift 后,shell 包装器会自动切换目录。

存储

每个托管工作区都有一个包含其标识符的 .rift 标记。一个 SQLite 注册表存储路径、父标识符和回收站条目。

默认创建的工区存储在与注册源根目录相邻的位置:

~/code/app/                         源工作区
~/code/.rifts/app/parser-fix/       创建的工作区
~/code/.rifts/app/.trash/            已删除工作区存储

JavaScript API

该包通过条件导出选择 Bun 或 Node 的 FFI 绑定。

import { create, list, remove, gc } from "rift-snapshot";

const workspace = create({ from: process.cwd(), name: "schema-work" });
console.log(list({ of: process.cwd() }));
remove({ at: workspace });
gc();

Node.js

Node 绑定需要 Node.js 26.1 或更高版本中的实验性 FFI API:

node --experimental-ffi app.mjs

如果使用 Node 的权限模型,还需传递 --allow-ffi

函数

init(options?: { at?: string; database?: string }): null
create(options?: { from?: string; name?: string; into?: string; database?: string }): string
remove(options?: { at?: string; all?: false; database?: string }): void
remove(options: { at?: string; all: true; database?: string }): string[]
list(options?: { of?: string; database?: string }): string[]
ancestors(options?: { of?: string; database?: string }): string[]
gc(options?: { database?: string }): string[]

JavaScript 的 init 函数只初始化 at 指定的目录;Git 根目录选择和 --here 属于 CLI 行为。

操作失败时会抛出 RiftError,包含 code 和相关的 path

开发

cargo test --workspace --locked
./scripts/install.sh

scripts/install.sh 会将优化的 CLI 二进制文件安装到 ${CARGO_HOME:-$HOME/.cargo}/bin/rift

许可证

MIT

相似文章

Croft - TUI VSCode 克隆

Lobsters Hottest

Croft 是一个 VS Code 风格的三窗格工作区,完全在终端中运行,使用 Rust 构建,具备 tree-sitter 语法高亮、图像/PDF/电子表格的内联预览以及嵌入式 shell。

@laogui: 经过几天使用,我可以毫不夸张地说:Rebased 就是目前最强的 Git 图形化客户端。 用过 JetBrains 系列 IDE 的朋友都知道,它的 Git 功能体验非常好——尤其是 Diff 功能。但这几年 JetBrains 在 AI…

X AI KOLs Timeline

Rebased 是一款基于 JetBrains IntelliJ 社区版构建的开源 Git 图形化客户端,砍掉了所有语言相关功能,只保留并优化了 Git 工具,提供了顶级的 Diff、Review、交互式 Rebase 和冲突解决体验,免费使用且零学习成本。