gitbutlerapp/gitbutler · error
Could not get a tree of all applied virtual branches merged
Error message
Could not get a tree of all applied virtual branches merged
What it means
get_workdir_tree reconstructs the working-directory tree by merging all applied virtual branches at a given snapshot commit. When the computed tree cannot be produced (tree_from_applied_vbranches fails) and the cache lookup misses, this error is thrown. It means GitButler could not materialize a coherent merged tree for the snapshot being restored.
Solutions
- Run `git fsck` and `git gc --prune=now` alternatives carefully: first confirm the underlying commits exist (`git cat-file -t <commit>`); restore missing objects from a remote/backup if pruned.
- Try restoring an adjacent (earlier or later) snapshot instead of the failing one.
- Use `but` CLI to list snapshots and pick one whose branches are intact.
- As a last resort, capture the current branch state manually with git and re-initialize the GitButler workspace.
Defensive patterns
Strategy: retry
Validate before calling
// ensure snapshot commit still exists before restore
repo.find_commit(snapshot_commit_id)
.map_err(|_| "snapshot commit is missing; pick another snapshot")?; Try / catch
match restore_snapshot_result {
Err(e) if e.to_string().contains("tree of all applied virtual branches merged") => {
// try an adjacent snapshot or fall back to git-level restore
restore_adjacent_snapshot()?
}
other => other,
} Prevention
- Run periodic `git fsck` and avoid aggressive gc settings that prune objects referenced by virtual branches.
- Restore snapshots soon after creating them rather than after unrelated rebases.
- Keep a backup/push of branches before performing undo/restore operations.
When it happens
Trigger: Calling restore_snapshot when tree_from_applied_vbranches returns Err for the snapshot commit — e.g. conflicting virtual branches, missing commits underneath the virtual branches, or a corrupted oplog snapshot — so neither the cache population nor the direct call yields a tree.
Common situations: Restoring an old undo snapshot whose virtual branches reference commits that were garbage-collected or rebased away; heavily conflicted multi-branch states at snapshot time; interrupted oplog writes.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- cannot snapshot a null target commit id
- Commit is not a snapshot
- Invalid conflict stage
- snapshot additional ref is not a local branch
- targetCommitId in project_meta.toml is null
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/2e214e5c37975da2.
Report an issue: GitHub.
Appendix: source
Thrown at crates/gitbutler-oplog/src/oplog.rs:406
if let Some(details) = details
&& details.version == Version(3)
{
let worktree_id = get_v3_workdir_tree(snapshot_commit.tree()?)?.context(format!(
"no entry at 'worktree' on sha {:?}, version: {:?}",
&snapshot_commit.id(),
&details.version,
))?;
return Ok(worktree_id);
}
match wd_trees_cache {
Some(cache) => {
if let Entry::Vacant(entry) = cache.entry(snapshot_commit.id)
&& let Ok(tree_id) = tree_from_applied_vbranches(repo, snapshot_commit.id)
{
entry.insert(tree_id);
}
cache.get(&snapshot_commit.id).copied().ok_or_else(|| {
anyhow!("Could not get a tree of all applied virtual branches merged")
})
}
None => tree_from_applied_vbranches(repo, snapshot_commit.id),
}
}
struct IndexTrees {
index: gix::ObjectId,
conflicts: Option<gix::ObjectId>,
}
fn write_index_trees(ctx: &Context) -> Result<IndexTrees> {
let repo = ctx.repo.get()?;
let index = repo.index_or_empty()?;
// The detached editor writes trees without checking that each entry's blob exists
// locally, which it may not, e.g. for unfetched files in a partial clone with a
// sparse checkout.
let mut tree = repo.empty_tree().edit()?.detach();View on GitHub (pinned to 58e5313667)