gitbutler
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitButler CLI Guide
GitButler CLI 指南
GitButler () is a modern Git client that makes history manipulation safe and reversible.
butGitButler()是一款现代化Git客户端,让历史操作变得安全且可撤销。
but[IMPORTANT] Detect GitButler Workspace
[重要] 检测GitButler工作区
Before running any git commands, check if GitButler is active:
bash
git branch --show-currentIf the result is :
gitbutler/workspace- [PREFER] commands when equivalent exists (commit, squash, undo, amend)
but - [OK] Native git for operations doesn't cover (cherry-pick, stash, tag, revert, blame)
but - [CAUTION] Some git commands can corrupt virtual branch state (see below)
Git Command Guidelines:
Prefer | Use | Use |
|---|---|---|
| | |
| | |
| | |
| | |
| | |
Why prefer when available? GitButler manages virtual branches through its workspace:
but- commands maintain virtual branch tracking
but - and oplog provide safer recovery
but undo - Some raw git commands can corrupt the virtual branch state
Quick detection pattern:
bash
undefined在运行任何Git命令之前,请检查GitButler是否处于激活状态:
bash
git branch --show-current如果结果为:
gitbutler/workspace- [优先] 当存在等效命令时使用命令(commit、squash、undo、amend)
but - [允许] 原生Git用于不支持的操作(cherry-pick、stash、tag、revert、blame)
but - [注意] 部分Git命令可能会破坏虚拟分支状态(见下文)
Git命令使用准则:
优先使用 | 可自由使用 | 谨慎使用 |
|---|---|---|
| | |
| | |
| | |
| | |
| | |
为什么有可用的命令时要优先使用? GitButler通过其工作区管理虚拟分支:
but- 命令可维护虚拟分支追踪
but - 和oplog提供更安全的恢复机制
but undo - 部分原生Git命令可能会破坏虚拟分支状态
快速检测脚本:
bash
undefinedAt start of git-related tasks, check:
在Git相关任务开始时,执行以下检查:
if [[ $(git branch --show-current) == "gitbutler/workspace" ]]; then
# Use 'but' commands instead of 'git'
fi
---if [[ $(git branch --show-current) == "gitbutler/workspace" ]]; then
# 使用'but'命令替代'git'
fi
---Key Advantages Over Git
相较于Git的核心优势
| Feature | Git | GitButler |
|---|---|---|
| Undo operations | Complex reflog | |
| Time travel | Risky reset | |
| Squash commits | | |
| Fix old commit | stash → rebase → amend | |
| Multiple features | Switch branches constantly | Virtual branches (simultaneous) |
| 功能特性 | Git | GitButler |
|---|---|---|
| 撤销操作 | 复杂的reflog | |
| 时光回溯 | 高风险的reset操作 | |
| 压缩提交 | | |
| 修改旧提交 | stash → rebase → amend | |
| 多特性并行开发 | 频繁切换分支 | 虚拟分支(可同时进行) |
Essential Commands
核心命令
Inspection (Always Start Here!)
状态检查(始终从这里开始!)
bash
but status # View workspace state (branches, commits, changes)
but oplog # View operation history (time-travel checkpoints)Status output explained:
╭┄00 [Unassigned Changes]
┊ g0 M calculator.py [LOCKED] 8ebedce ← File ID, status, dependency
┊
┊╭┄al [calculator-feature] ← Branch ID
┊● abc1234 Commit message ← Commit
├╯
┊
┴ 6e7da9e (common base) [origin/main]- ,
g0: File/change IDs (use withh0)but rub - ,
al: Branch IDsut - : GitButler detected this change belongs to that commit
[LOCKED] <sha> - ,
M,A: Modified, Added, DeletedD
bash
but status # 查看工作区状态(分支、提交、变更)
but oplog # 查看操作历史(时光回溯检查点)状态输出说明:
╭┄00 [未分配变更]
┊ g0 M calculator.py [LOCKED] 8ebedce ← 文件ID、状态、依赖提交
┊
┊╭┄al [calculator-feature] ← 分支ID
┊● abc1234 提交信息 ← 提交记录
├╯
┊
┴ 6e7da9e (公共基线) [origin/main]- ,
g0: 文件/变更ID(与h0配合使用)but rub - ,
al: 分支IDut - : GitButler检测到该变更属于此提交
[LOCKED] <sha> - ,
M,A: 已修改、已添加、已删除D
The rub
Multi-Tool
rub多功能工具rub
rubThe command performs different operations based on source/target types:
rub| Source | Target | Operation | Example |
|---|---|---|---|
| File | Branch | Assign | |
| File | Commit | Amend | |
| Commit | Commit | Squash | |
| Commit | Branch | Move | |
Squash workflow:
bash
but status # Get current SHAs
but rub <source-sha> <target-sha> # Squash source INTO target
but reword <new-sha> -m "Combined message" # Update messagerub| 源类型 | 目标类型 | 操作 | 示例 |
|---|---|---|---|
| 文件 | 分支 | 分配 | |
| 文件 | 提交 | 修改 | |
| 提交 | 提交 | 压缩 | |
| 提交 | 分支 | 移动 | |
压缩提交流程:
bash
but status # 获取当前提交SHA
but rub <源SHA> <目标SHA> # 将源提交压缩到目标提交中
but reword <新SHA> -m "合并后的提交信息" # 更新提交信息Smart Amending with absorb
absorb智能修改提交:absorb
absorbWhen you modify code, GitButler detects which commit introduced those lines:
bash
undefined当你修改代码时,GitButler会检测到这些代码行来自哪个提交:
bash
undefinedEdit a file, then check status
编辑文件,然后查看状态
but status
but status
Shows: g0 M file.py [LOCKED] abc123 ← Detected dependency!
输出示例:g0 M file.py [LOCKED] abc123 ← 检测到依赖关系!
Auto-amend to the correct commit
自动将修改合并到对应提交
but absorb
GitButler automatically:
1. Analyzes which lines changed
2. Finds the commit that introduced them
3. Amends the change into that commit
4. Rebases all dependent commits
---but absorb
GitButler会自动执行以下操作:
1. 分析哪些代码行被修改
2. 找到引入这些代码行的提交
3. 将修改合并到该提交中
4. 对所有依赖提交执行变基操作
---Commit Editing
提交编辑
bash
but reword <sha> -m "new message" # Edit commit message (auto-rebases)
but absorb # Auto-amend changes to correct commits
but absorb <file-id> # Absorb specific file onlybash
but reword <sha> -m "新的提交信息" # 编辑提交信息(自动执行变基)
but absorb # 自动将变更合并到对应提交
but absorb <文件ID> # 仅合并指定文件的变更Undo & Recovery (Time Travel)
撤销与恢复(时光回溯)
bash
but undo # Undo last operation (one step back)
but oplog snapshot -m "checkpoint" # Create named checkpoint
but restore <sha> --force # Restore to any oplog snapshotThe oplog is your time machine:
bash
but oplog # See all operationsbash
but undo # 撤销上一次操作(回退一步)
but oplog snapshot -m "检查点" # 创建命名检查点
but restore <sha> --force # 恢复到任意oplog快照状态oplog是你的时光机器:
bash
but oplog # 查看所有操作记录Output:
输出示例:
7f8e652 [SQUASH] SquashCommit
7f8e652 [SQUASH] 压缩提交
abc1234 [CREATE] CreateCommit
abc1234 [CREATE] 创建提交
def5678 [MOVE_HUNK] MoveHunk
def5678 [MOVE_HUNK] 移动代码块
but restore 7f8e652 --force # Go back to that point
Even undos are tracked! You can undo an undo.
---but restore 7f8e652 --force # 回退到该操作点
即使是撤销操作也会被记录!你可以撤销之前的撤销操作。
---Virtual Branches (Work on Multiple Features)
虚拟分支(并行开发多特性)
Create and manage branches:
bash
but branch new <name> # Create virtual branch
but branch list # List all branches
but branch unapply <id> # Hide branch temporarily
but branch apply <id> # Show branch againWork on multiple features simultaneously:
bash
undefined创建和管理分支:
bash
but branch new <名称> # 创建虚拟分支
but branch list # 列出所有分支
but branch unapply <ID> # 临时隐藏分支
but branch apply <ID> # 重新显示分支同时开发多个特性:
bash
undefinedEdit files for different features
为不同特性编辑文件
vim feature-a.py
vim feature-b.py
vim feature-a.py
vim feature-b.py
Check status - assign to different branches
查看状态 - 将变更分配到不同分支
but status
but status
g0 M feature-a.py
g0 M feature-a.py
h0 M feature-b.py
h0 M feature-b.py
but rub g0 al # Assign to branch 'al'
but rub h0 ut # Assign to branch 'ut'
but rub g0 al # 将变更分配到分支'al'
but rub h0 ut # 将变更分配到分支'ut'
Commit to each branch
分别向每个分支提交
but commit al -m "Feature A" --only
but commit ut -m "Feature B" --only
**No context switching!** Both branches are active simultaneously.
---but commit al -m "完成特性A" --only
but commit ut -m "完成特性B" --only
**无需切换上下文!** 两个分支可同时处于激活状态。
---Committing
提交操作
bash
but commit <branch> -m "message" # Commit ALL uncommitted changes
but commit <branch> -m "message" --only # Commit ONLY assigned changes
but commit -c -m "message" # Create new branch and commit[CAUTION] Important: Without , includes ALL uncommitted changes!
--onlybut commitbash
but commit <分支> -m "提交信息" # 提交所有未提交的变更
but commit <分支> -m "提交信息" --only # 仅提交已分配的变更
but commit -c -m "提交信息" # 创建新分支并提交[注意] 重要提示:如果不添加参数,会包含所有未提交的变更!
--onlybut commitQuick Reference: Git → But
快速参考:Git → But 命令映射
| Git Command | But Command |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| N/A | |
| N/A | |
| N/A | |
| Git命令 | But命令 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| 无对应命令 | |
| 无对应命令 | |
| 无对应命令 | |
Common Workflows
常见工作流
Fix typo in old commit message
修复旧提交信息中的拼写错误
bash
but status # Find the commit SHA
but reword <sha> -m "Fixed message"bash
but status # 找到目标提交的SHA
but reword <SHA> -m "修正后的提交信息"Squash multiple commits
压缩多个提交
bash
but status # Get SHAs
but rub <source> <target> # Squash
but reword <new-sha> -m "Combined" # Update messagebash
but status # 获取所有相关提交的SHA
but rub <源SHA> <目标SHA> # 压缩提交
but reword <新SHA> -m "合并后的提交信息" # 更新提交信息Amend change to old commit
将修改合并到旧提交
bash
undefinedbash
undefinedEdit the file, then:
编辑文件,然后执行:
but status # Check for [LOCKED] dependency
but absorb # Auto-amend
undefinedbut status # 检查是否有[LOCKED]依赖标记
but absorb # 自动合并到对应提交
undefinedRecover from mistake
从错误操作中恢复
bash
but undo # Quick: undo last operationbash
but undo # 快速撤销上一次操作OR
或者
but oplog # Find the right snapshot
but restore <sha> --force # Go back in time
---but oplog # 找到合适的快照
but restore <SHA> --force # 回退到指定状态
---Error Handling
错误处理
Common Errors and Recovery
常见错误与恢复方法
| Error | Cause | Recovery |
|---|---|---|
| GitButler not initialized | Run |
| "Branch not found" | Virtual branch deleted/renamed | Run |
| "Conflict detected" | Merge conflict during operation | Resolve conflicts in files, then |
| "Uncommitted changes" | Operation blocked by dirty state | Commit or stash changes first |
| Command hangs | Large repo or network issue | Wait, or Ctrl+C and retry |
| 错误信息 | 原因 | 恢复方法 |
|---|---|---|
| GitButler未初始化 | 运行 |
| "分支未找到" | 虚拟分支已被删除/重命名 | 运行 |
| "检测到冲突" | 操作过程中出现合并冲突 | 手动解决文件中的冲突,然后执行 |
| "存在未提交的变更" | 操作因工作区未清理而被阻止 | 先提交或暂存变更 |
| 命令执行卡住 | 仓库过大或网络问题 | 等待一段时间,或按Ctrl+C后重试 |
Recovery Commands
恢复命令
bash
but undo # Undo last operation (safe, always works)
but oplog # View all operations for recovery points
but restore <sha> --force # Restore to any previous state
but oplog snapshot list # List named checkpointsbash
but undo # 撤销上一次操作(安全,始终可用)
but oplog # 查看所有操作记录以找到恢复点
but restore <sha> --force # 恢复到任意之前的状态
but oplog snapshot list # 列出所有命名检查点When to Use undo
vs restore
undorestore何时使用undo
vs restore
undorestore- : Quick single-step rollback. Use when the last operation went wrong.
but undo - : Time-travel to any point. Use when you need to go back multiple operations or to a named checkpoint.
but restore
[INFO] The oplog tracks everything, including undos. You can always recover!
- : 快速单步回退。适用于上一次操作出现错误的场景。
but undo - : 回退到任意历史节点。适用于需要回退多步操作或回到指定命名检查点的场景。
but restore
[提示] oplog会记录所有操作,包括撤销操作。你永远都能恢复到之前的状态!
Claude Code Hooks Integration
Claude Code Hooks 集成
GitButler integrates with Claude Code through hooks (, , ) that automatically manage commits during AI-assisted development sessions.
but claude pre-toolbut claude post-toolbut claude stopKey benefits:
- Auto-assigns changes to appropriate branches
- Generates commit messages from user prompts
- Eliminates manual during sessions
but commit
For detailed configuration and setup instructions, see .
references/hooks.mdGitButler通过钩子命令(、、)与Claude Code集成,可在AI辅助开发会话中自动管理提交。
but claude pre-toolbut claude post-toolbut claude stop核心优势:
- 自动将变更分配到合适的分支
- 根据用户提示生成提交信息
- 消除会话中手动执行的需求
but commit
如需详细配置和设置说明,请查看。
references/hooks.mdReference Files
参考文档
For detailed documentation, see:
- - Quick command reference with git → but mappings
references/cheatsheet.md - - Comprehensive step-by-step workflows
references/tutorial.md - - Claude Code hooks setup guide
references/hooks.md
如需更详细的文档,请查看:
- - 快速命令参考,包含Git→But命令映射
references/cheatsheet.md - - 全面的分步工作流指南
references/tutorial.md - - Claude Code钩子设置指南
references/hooks.md