gitbutlerapp/gitbutler · error

Could not find stack containing commit

Error message

Could not find stack containing commit {commit_ref}

What it means

`enter_resolution` in the resolve command is given a commit reference but could not locate any stack (workspace branch group) containing that commit, so `found_stack_id` stays None. The error tells the user the commit they referenced is not part of any current workspace stack.

Solutions

  1. Run `but log` / `but status` to list current stacks and copy the correct commit id
  2. Confirm the commit still belongs to an active stack (it may have been merged or assigned to another branch)
  3. Retry with the full commit id or an unambiguous reference
  4. Re-open/refresh the workspace if commit ids changed after a rebase

Example fix

// before
but resolve ab12   # ambiguous or stale short id
// error: Could not find stack containing commit ab12
// after
but log            # find the commit inside an active stack
but resolve 3f9c1ab...
Defensive patterns

Strategy: validation

Validate before calling

// verify the commit is in an active stack before resolving
but log | grep -q "$(git rev-parse --short "$COMMIT")" || { echo 'Commit not in any stack'; exit 1; }

Try / catch

if ! OUT=$(but resolve "$COMMIT" 2>&1); then
  case "$OUT" in
    *"Could not find stack"*) echo "Commit $COMMIT is not in a stack; check 'but log' for current ids";;
    *) echo "$OUT";;
  esac
fi

Prevention

When it happens

Trigger: Calling `but resolve <commit-ref>` (directly or via check_and_prompt_for_conflicts) with a commit id/short id/branch ref that does not exist in the workspace's stacks — e.g. a fully merged commit, a typo'd short id, or a commit on a branch outside the workspace.

Common situations: Typing an abbreviated commit id that matches a commit not in any stack; referencing a commit after the stack was merged or archived; stale reference after workspace rebase/rebuild changed commit ids.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/f7808e87247a652c. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/legacy/resolve.rs:239

            let traversal = head
                .tip
                .attach(&repo)
                .ancestors()
                .sorting(Sorting::BreadthFirst)
                .all()?;

            for info in traversal {
                let info = info?;
                if info.id == commit_gix_oid {
                    found_stack_id = stack.id;
                    break 'outer;
                }
            }
        }
    }

    let stack_id = found_stack_id
        .ok_or_else(|| anyhow::anyhow!("Could not find stack containing commit {commit_ref}"))?;

    drop(commit);
    drop(repo);

    // Enter edit mode
    enter_edit_mode(ctx, commit_gix_oid, stack_id).context("Failed to enter edit mode")?;

    // Show checkout message
    if let Some(out) = out.for_human() {
        writeln!(
            out,
            "{} {}",
            t.important.paint("Checking out conflicted commit"),
            commit_ref
        )?;
    }

    // Now show the same status as `but resolve status` would show

View on GitHub (pinned to 58e5313667)