gitbutlerapp/gitbutler · error

Failed to find reference

Error message

Failed to find reference {target} in rebase editor

What it means

Editor::select_reference looks up a git reference by its full name in the rebase editor's graph and returns a Selector. This error is thrown when the reference is not present in the graph being edited, i.e. try_select_reference returned None.

Solutions

  1. Confirm the fully qualified ref name (refs/heads/...) and that the ref exists in the repo
  2. Use try_select_reference and handle None explicitly
  3. Rebuild the Editor's graph including the reference before selecting it

Example fix

// before
let selector = editor.select_reference(target_ref)?;
// after
let Some(selector) = editor.try_select_reference(target_ref) else {
    anyhow::bail!("ref {target_ref} not present in rebase graph");
};
Defensive patterns

Strategy: validation

Validate before calling

fn ref_in_graph(editor: &Editor<...>, target: &gix::refs::FullNameRef) -> bool {
    editor.try_select_reference(target).is_some()
}

Try / catch

let selector = editor.try_select_reference(target)
    .ok_or_else(|| anyhow::anyhow!("reference {target} not loaded into rebase graph"))?;

Prevention

When it happens

Trigger: Calling select_reference with a refs::FullNameRef (e.g. refs/heads/my-branch) that the editor's graph does not contain — the ref wasn't included when the graph was constructed, or the ref name is wrong/typo'd.

Common situations: Rebasing scripts referencing a branch that was deleted or renamed, refs on remote namespaces not loaded into the graph, or passing a partial ref name instead of a fully qualified one.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at crates/but-rebase/src/graph_rebase/mutate.rs:249

        editor.select_reference(self.as_ref())
    }
}

/// Operations for mutating the commit graph
impl<M: RefMetadata> Editor<'_, '_, M> {
    /// Get a selector to a particular commit in the graph
    pub fn select_commit(&self, target: gix::ObjectId) -> Result<Selector> {
        match self.try_select_commit(target) {
            Some(selector) => Ok(selector),
            None => Err(anyhow!("Failed to find commit {target} in rebase editor")),
        }
    }

    /// Get a selector to a particular reference in the graph
    pub fn select_reference(&self, target: &gix::refs::FullNameRef) -> Result<Selector> {
        match self.try_select_reference(target) {
            Some(selector) => Ok(selector),
            None => Err(anyhow!(
                "Failed to find reference {target} in rebase editor"
            )),
        }
    }

    /// Get a selector to a particular commit in the graph
    pub fn try_select_commit(&self, target: gix::ObjectId) -> Option<Selector> {
        for node_idx in self.graph.node_indices() {
            if let Step::Pick(Pick { id, .. }) = self.graph[node_idx]
                && id == target
            {
                return Some(self.new_selector(node_idx));
            }
        }

        None
    }

View on GitHub (pinned to 58e5313667)