gitbutlerapp/gitbutler · error
Visible worktree HEAD changed shape during the edit…
Error message
Visible worktree {worktree_name} HEAD changed shape during the edit: expected {}, got {} What it means
During materialization of a rebased graph, the head of a visible (non-primary) worktree is checked to still point at the reference recorded in the original graph. If the actual ref differs from the expected one, the operation bails because silently re-parenting or rewiring a worktree whose HEAD moved could corrupt the user's working state. The library refuses to guess which shape is correct.
Solutions
- Re-run the operation so a fresh graph/worktree snapshot is captured before materializing
- Check `git worktree list` and `git -C <worktree> rev-parse --symbolic-full-name HEAD` to see what changed and restore the expected ref
- Retry with no other git/but processes touching the worktree concurrently
- If the change was intentional, rebuild the editor history so the new HEAD is the expected reference
Example fix
// before: HEAD moved behind your back -> error
editor.materialize()?;
// after: verify and restore before materializing
let actual = repo.find_worktree(&name)?.head()?.kind;
if actual != expected_ref { /* re-sync worktree HEAD to expected_ref */ }
editor.materialize()?; Defensive patterns
Strategy: validation
Validate before calling
let actual = repo.find_worktree(name)?.head()?;
let actual_ref = actual.referenced_name().map(|r| r.to_owned());
if actual_ref != expected_ref { /* re-sync or restart operation */ } Type guard
fn matches_expected(actual: Option<&gix::refs::FullNameRef>, expected: &Option<gix::refs::FullName>) -> bool {
match (expected, actual) {
(None, None) => true,
(Some(e), Some(a)) => e.as_ref() == a,
_ => false,
}
} Prevention
- Avoid concurrent git/but operations on the same worktree
- Snapshot and re-validate worktree HEAD immediately before materialize
- Re-create the editor after any manual checkout in a worktree
When it happens
Trigger: Calling Editor::materialize (via the materialize flow) when a worktree named in the graph has had its HEAD changed between capture of the graph (e.g. checkout_target snapshot) and materialization: expected_ref is None (detached) but actual_ref is a branch, or expected a branch name but got detached or a different branch.
Common situations: Another process (IDE, but CLI, git command) checked out a different branch or detached HEAD in the worktree while a graph rebase/materialize was in flight; long-running editor sessions where a user manually moves the worktree HEAD; stale worktree metadata after a concurrent operation.
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
- Visible worktree changed since the editor was created…
- another pre-commit hook is already using the repository…
- Base commit must exist if provided
- `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/668d6005e363d87e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-rebase/src/graph_rebase/materialize.rs:144
/// one, validated against the shape recorded at editor creation.
pub(super) fn linked_checkout_specs(&self) -> Result<Vec<LinkedCheckoutSpec>> {
let mut specs = Vec::new();
for checkout in &self.checkouts {
let Checkout::Worktree {
worktree_name,
selector,
ref_name: expected_ref,
initial_head,
merge_base_override,
} = checkout
else {
continue;
};
let (target, actual_ref) = self
.checkout_target(*selector)?
.with_context(|| format!("Visible worktree {worktree_name} HEAD was removed"))?;
if actual_ref != *expected_ref {
bail!(
"Visible worktree {worktree_name} HEAD changed shape during the edit: \
expected {}, got {}",
expected_ref
.as_ref()
.map_or_else(|| "detached".into(), ToString::to_string),
actual_ref
.as_ref()
.map_or_else(|| "detached".into(), ToString::to_string)
);
}
specs.push(LinkedCheckoutSpec {
name: worktree_name.clone(),
initial_head: *initial_head,
ref_name: expected_ref.clone(),
target,
merge_base_override: *merge_base_override,
});
}View on GitHub (pinned to 58e5313667)