gitbutlerapp/gitbutler · error

Cannot unapply branch by checking out conflicted commit

Error message

Cannot unapply branch by checking out conflicted commit {new_head_id}

What it means

`safe_checkout` inspects the target commit before checking it out and aborts if it is a conflicted commit (contains conflict markers/conflict state recorded by GitButler). Checking out such a commit would put the worktree into a broken conflicted state during unapply.

Solutions

  1. Resolve or discard the conflicted commit(s) first (complete conflict resolution and commit)
  2. Choose a different, non-conflicted target to check out after unapply
  3. Abort the unapply and let the user fix conflicts in the UI before retrying

Example fix

// before
safe_checkout(repo, new_head_id, options)?;
// after
if but_core::Commit::from_id(new_head_id.attach(repo))?.is_conflicted() {
    anyhow::bail!("resolve conflicts before unapply");
}
safe_checkout(repo, new_head_id, options)?;
Defensive patterns

Strategy: validation

Validate before calling

fn is_clean_target(repo: &gix::Repository, id: gix::ObjectId) -> bool {
    !but_core::Commit::from_id(id.attach(repo)).map_or(true, |c| c.is_conflicted())
}

Prevention

When it happens

Trigger: Unapply's internal checkout step (`safe_checkout_ref_to_checkout` / `checkout_and_update_workspace_ref`) resolved to a commit id for which `but_core::Commit::is_conflicted()` is true.

Common situations: Unapplying a branch whose merge state produced conflicted commits; target ref pointing at a commit created mid-conflict-resolution.

Related errors


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

Appendix: source

Thrown at crates/but-workspace/src/branch/unapply.rs:647

            if selected
                .as_ref()
                .is_none_or(|(best_generation, _)| generation < *best_generation)
            {
                selected = Some((generation, ref_to_checkout));
            }
        }
        Ok(selected.map(|(_, ref_to_checkout)| ref_to_checkout))
    }

    /// Run `safe_checkout`, but provide better error messages if the commit to checkout
    /// is conflicted.
    fn safe_checkout(
        repo: &gix::Repository,
        new_head_id: gix::ObjectId,
        options: but_core::worktree::checkout::Options,
    ) -> anyhow::Result<but_core::worktree::checkout::Outcome> {
        if but_core::Commit::from_id(new_head_id.attach(repo))?.is_conflicted() {
            bail!("Cannot unapply branch by checking out conflicted commit {new_head_id}");
        }
        but_core::worktree::safe_checkout_from_head(new_head_id, repo, options)
    }

    /// Check out `ref_to_checkout` using the workspace traversal entrypoint as the
    /// current worktree/index source.
    ///
    /// `ws` must be the workspace projection for the currently checked-out `HEAD`.
    /// Its graph entrypoint is therefore the commit the index and worktree are
    /// expected to match before checkout. This matters when `HEAD` points at a
    /// stack segment inside the workspace rather than the workspace tip.
    ///
    /// The helper only updates the index/worktree according to `options`; callers
    /// remain responsible for any subsequent `HEAD`, reference, metadata, and
    /// projection updates.
    fn safe_checkout_ref_to_checkout(
        repo: &gix::Repository,
        ref_to_checkout: &RefToCheckout,

View on GitHub (pinned to 58e5313667)