使用无分支
- 作者仓库星标 0
- 作者仓库 plugins
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @0-xcf · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# git-branchless
Stacked-diffs workflow for Git. Commits are the unit of work, not branches. Think Mercurial/Phabricator-style development.
## Mental Model
- **Stack**: a chain of draft commits off `main()`/`master`. Stacks can branch.
- **Draft commits**: your in-progress work. Visible in smartlog even without branch names.
- **Public commits**: merged into main. Immutable.
- Rebases happen **in-memory** first (fast, safe). Falls back to on-disk only if needed.
- `git undo` can reverse almost any operation.
## Command Quick Reference
| Task | Command |
|------|---------|
| View commit graph | `git sl` |
| Go to specific commit | `git checkout <hash>` or `git branchless switch <hash>` |
| Navigate down stack (relative) | `git prev [n]` (interactive if stack branches) |
| Navigate up stack (relative) | `git next [n]` (interactive if stack branches) |
| Fuzzy-search checkout | `git branchless switch -i` |
| Create commit | `git record -m "msg"` |
| Insert commit mid-stack | `git record --insert -m "msg"` |
| Amend HEAD commit | `git amend` (stage changes first) |
| Amend + keep descendants identical | `git amend --reparent` |
| Reword commit message | `git reword -m "new msg"` |
| Move/rebase commits | `git move -s <src> -d <dest>` |
| Reorder: swap A and B | `git move -x <B> -d <parent-of-A>` |
| Squash into dest | `git move -x <src> -d <dest> --fixup` |
| Insert between dest and children | `git move -s <src> -d <dest> --insert` |
| Fix orphaned commits after amend | `git restack` |
| Sync all stacks onto updated main | `git sync --pull` |
| Sync without fetching | `git sync` |
| Push existing PR branches | `git submit` |
| Create new PR branches | `git submit --create` |
| Push as draft PRs | `git submit --create --draft` |
| Hide/discard a stack | `git hide -r <commit>` |
| Recover hidden commits | `git unhide <commit>` |
| Undo last operation | `git undo` |
## Critical Distinctions
**`git sync` vs `git restack`** - agents confuse these constantly:
- `git sync` = rebase stacks onto **updated main** (runs `git fetch` + in-memory rebase, NOT `git pull` - so `branch.autosetuprebase` is irrelevant)
- `git restack` = fix **orphaned descendants** after you amend/reword a mid-stack commit
- After amending mid-stack: `git restack`
- After fetching new main: `git sync --pull`
**`git move` modes:**
- `-s/--source`: move commit **and all descendants**
- `-b/--base`: move entire branch from merge-base (default if nothing specified)
- `-x/--exact`: move **only** specified commits, leave descendants in place
## Revset Language
Revsets select commits. Used by `git sl`, `git move`, `git submit`, `git query`, etc.
### Essential Functions
| Revset | Meaning |
|--------|---------|
| `@` | HEAD |
| `stack()` | Current stack (default for many commands) |
| `draft()` | All draft (non-public) commits |
| `main()` | Tip of main branch |
| `ancestors(x)` / `::x` | All ancestors of x |
| `descendants(x)` / `x::` | All descendants of x |
| `children(x)` | Immediate children |
| `parents(x)` | Immediate parents |
| `branches(pattern)` | Commits with matching branch names |
| `message(pattern)` | Commits matching message text |
| `paths.changed(pattern)` | Commits touching matching file paths |
| `author.date(pattern)` | Commits by date |
### Operators
| Op | Meaning |
|----|---------|
| `x + y`, `x \| y` | Union |
| `x & y` | Intersection |
| `x - y` | Difference (spaces required! `foo-bar` = branch name) |
| `x % y` | Only: ancestors of x not ancestors of y |
### Date/Text Patterns
```
author.date("after:1 week ago") # relative dates
author.date("before:2025-01-01") # absolute dates
message("substr:fix") # substring (default)
message("regex:feat.*auth") # regex
paths.changed("glob:src/**/*.ts") # glob
```
## Common Workflows
### Amend a mid-stack commit
```bash
git checkout <hash> # go to the target commit (or git prev N for relative)
# make edits, git add
git amend # amend in place
git restack # rebase descendants onto amended commit
git checkout <stack-tip> # return to where you were
```
### Create a new stack for independent work
```bash
git branchless switch master # go to main
# make changes
git record -m "feat: new thing" -c my-branch # commit + create branch
```
### Submit stacked PRs to GitHub
```bash
git submit --create --forge github # first time: create PRs
git submit # subsequent: update existing PRs
```
### Sync after main branch updated
```bash
git sync --pull # fetch + rebase all stacks onto new main
```
### Move a stack on top of another
```bash
git move -s <root-of-stack-2> -d <tip-of-stack-1>
```
## What NOT To Do
- **Don't use `git rebase -i`** for reordering/squashing. Use `git move` instead.
- **Don't create branches manually** for stacked work. Commits are the unit; branches are created at submit time.
- **Don't confuse `git restack` with `git sync`**. Restack = fix orphans. Sync = update to new main.
- **Don't use `git merge`** for incorporating upstream changes. Use `git sync --pull`.
章节与文件索引
按说明文件中的顺序排列。
心智模型
命令快速参考
关键区别
修订集语言
基本功能
文件/命令 -> main() · master · git undo · git sl · git checkout <hash> · git branchless switch <hash> · git prev [n] · git next [n]
内容校验值 -> 978e60eddaf9
当前原文的自动摘译,尚未人工审校。
心智模型
堆栈:一系列草案提交
main()/master。堆栈可以分支。草稿提交:您正在进行的工作。即使没有分支名称,在 smartlog 中也可见。公共提交:合并到 main 中。不变的。变基首先在内存中发生(快速、安全)。仅在需要时回退到磁盘上。git undo几乎可以逆转任何操作。命令快速参考
任务 · 命令视图提交图 ·
git sl转到特定提交 ·git checkout <hash>或git branchless switch <hash>向下导航堆栈(相对) ·git prev [n](如果堆栈分支则交互式) 向上导航堆栈(相对) ·git next [n](如果堆栈分支则交互式)关键区别
git syncvsgit restack- 代理不断混淆这些:git sync= 将堆栈变基到更新的 main (运行git fetch+ 内存中变基,而不是git pull- 所以branch.autosetuprebase不相关)git restack= 在修改/重写 a 后修复孤立的后代堆栈中提交修改堆栈中后:git restack获取新的 main 后:git sync --pull修订集语言
Revsets 选择提交。由
git sl、git move、git submit、git query等使用。基本功能
Revset · 含义
@· HEADstack()· 当前堆栈(许多命令的默认值)draft()· 所有草稿(非公开)提交main()· 主分支提示