gitbutlerapp/gitbutler · error
Visible worktree changed since the editor was created…
Error message
Visible worktree {} changed since the editor was created: expected {} at {}, got {} at {} What it means
Before materializing a rebase plan, the library re-opens each visible worktree and verifies its checked-out ref and HEAD still match what was recorded when the editor was created. If either changed, applying the plan could clobber concurrent work, so it aborts with expected vs actual ref and commit ids.
Solutions
- Recreate the editor from the current workspace state and re-apply the intended changes
- Inspect the reported expected/actual ref and commit, then restore the worktree to the expected state (git checkout <ref>; git reset --hard <id>) if safe
- Avoid mutating worktrees while a graph rebase editor is alive; perform mutations, then create the editor
- Re-run materialize immediately after editor creation to minimize the race window
Example fix
// before: editor created, worktree mutated elsewhere, then
materialize(editor, plan)?;
// after: re-validate / recreate
match materialize(editor, plan) {
Ok(r) => r,
Err(_) => {
let editor = create_with_opts(&fresh_workspace, &tips, opts)?;
materialize(editor, plan)?
}
} Defensive patterns
Strategy: try-catch
Validate before calling
for spec in &editor.visible_checkouts() {
let repo = gix::open(worktree_path(&repo, &spec.name))?;
anyhow::ensure!(
repo.head_name().ok().as_ref() == Some(&spec.ref_name)
&& repo.head_id().ok().map(|i| i.detach()) == Some(spec.initial_head),
"worktree {} drifted since editor creation", spec.name
);
} Try / catch
match materialize(&repo, editor, plan) {
Ok(r) => r,
Err(e) if e.to_string().contains("changed since the editor was created") => {
eprintln!("worktree moved; recreating editor from current state");
let ws = but_workspace::refresh(&repo)?;
let editor = create_with_opts(&ws, &tips, opts)?;
materialize(&repo, editor, plan)?
}
Err(e) => return Err(e),
} Prevention
- Don't run git checkout/reset in worktrees while a rebase editor is open
- Materialize promptly after creating the editor
- Recreate the editor after any external git mutation
When it happens
Trigger: Calling `materialize` (which runs `open_linked_checkout_repos`) after the editor was created, but in the meantime a worktree had its HEAD moved — e.g. a branch was checked out, reset, force-pushed, or the worktree went detached.
Common situations: Another terminal or IDE ran git checkout/reset in a worktree while the rebase editor was open; a background fetch updated a branch; long-running operations with slow user interaction allowing the repo state to drift.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Some selected changes no longer match the worktree's…
- Visible worktree HEAD changed shape during the edit…
- another pre-commit hook is already using the repository…
- `but setup` cannot run from a linked worktree; run it from…
- Cannot currently work in repositories without a worktree
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/ed7bd745c2b75f03.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-rebase/src/graph_rebase/materialize.rs:90
repo: &gix::Repository,
specs: Vec<LinkedCheckoutSpec>,
) -> Result<Vec<LinkedCheckoutRepo>> {
if specs.is_empty() {
return Ok(Vec::new());
}
let proxies = repo.worktrees()?;
specs
.into_iter()
.map(|spec| {
let proxy = proxies
.iter()
.find(|proxy| proxy.id() == spec.name.as_bstr())
.with_context(|| format!("Visible worktree {} no longer exists", spec.name))?;
let worktree_repo = proxy.clone().into_repo()?;
let actual_ref = worktree_repo.head_name()?;
let actual_head = worktree_repo.head_id()?.detach();
if actual_ref != spec.ref_name || actual_head != spec.initial_head {
bail!(
"Visible worktree {} changed since the editor was created: \
expected {} at {}, got {} at {}",
spec.name,
spec.ref_name
.as_ref()
.map_or_else(|| "detached".into(), ToString::to_string),
spec.initial_head,
actual_ref
.as_ref()
.map_or_else(|| "detached".into(), ToString::to_string),
actual_head
);
}
Ok(LinkedCheckoutRepo {
repo: worktree_repo,
target: spec.target,
merge_base_override: spec.merge_base_override,
})View on GitHub (pinned to 58e5313667)