gitbutlerapp/gitbutler · error

cannot mark files from multiple commits

Error message

cannot mark files from multiple commits

What it means

Committed-file marks are additionally constrained to a single commit: the `CommittedFiles` list stores a `commit_id` on its head, and inserting a file from a different commit would silently create a mixed-selection apply. The code bails with 'cannot mark files from multiple commits' (and a foreign variant still bails with 'cannot mix mark sources').

Solutions

  1. Unmark the current committed files before marking files from a different commit.
  2. Perform one apply per commit: mark files of commit A, apply, then commit B.
  3. Fix selection UI to reset marks when the focused commit changes.

Example fix

// before: spanning commits
mark(file_from_commit_b)?; // head.commit_id == A -> bail
// after
if marks_head_commit() != Some(file.commit_id) {
    marks = Marks::Empty;
}
mark(file)?;
Defensive patterns

Strategy: try-catch

Validate before calling

fn can_insert_committed_file(marks: &Marks, f: &CommittedFileId) -> bool {
    match marks {
        Marks::Empty => true,
        Marks::CommittedFiles(files) => files.head.commit_id == f.commit_id,
        _ => false,
    }
}

Type guard

fn same_commit(m: &Marks, f: &CommittedFileId) -> bool {
    match m {
        Marks::Empty => true,
        Marks::CommittedFiles(files) => files.head.commit_id == f.commit_id,
        _ => false,
    }
}

Try / catch

if let Err(e) = marks.insert_committed_file(file) {
    let msg = e.to_string();
    if msg.contains("multiple commits") || msg.contains("cannot mix mark sources") {
        marks = Marks::Empty;
        marks.insert_committed_file(file)?;
    } else { return Err(e); }
}

Prevention

When it happens

Trigger: Inserting a `CommittedFileId` whose `commit_id` differs from the commit of the currently held `CommittedFiles` head — e.g. marking files from commit A, then marking a file from commit B in the same selection.

Common situations: TUI multi-commit list where the user marks files across several commits then applies; a mouse-drag or shift-click range spanning commits.

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


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

Appendix: source

Thrown at crates/but/src/command/legacy/status/tui/app/mark.rs:430

}

impl MarkStore<CommittedFileId> for Marks {
    type Error = anyhow::Error;

    fn contains_mark(&self, mark: &CommittedFileId) -> bool {
        self.as_committed_files()
            .is_some_and(|files| files.iter().any(|file| file == mark))
    }

    fn insert_mark(&mut self, mark: CommittedFileId) -> Result<(), Self::Error> {
        if self.contains_mark(&mark) {
            return Ok(());
        }
        match self {
            Self::Empty => *self = Self::CommittedFiles(NonEmpty::new(mark)),
            Self::CommittedFiles(files) => {
                if files.head.commit_id != mark.commit_id {
                    anyhow::bail!("cannot mark files from multiple commits");
                }
                files.push(mark);
            }
            _ => anyhow::bail!("cannot mix mark sources"),
        }
        Ok(())
    }

    fn remove_mark(&mut self, mark: &CommittedFileId) {
        let Self::CommittedFiles(files) = self else {
            return;
        };

        if remove_from_non_empty(files, |marked| marked == mark) {
            *self = Self::Empty;
        }
    }
}

View on GitHub (pinned to 58e5313667)