gitbutlerapp/gitbutler · warning

No uncommitted changes to discard

Error message

No uncommitted changes to discard

What it means

In the uncommitted branch of `but discard`, the worktree diff specs are reconciled and checked with `ensure!(!changes.is_empty())`. If there are no uncommitted changes matching the request, the CLI raises this error instead of starting a transaction that would do nothing.

Solutions

  1. Run `but` to confirm there are uncommitted changes before discarding
  2. Commit the changes (`but commit`) if you actually wanted to keep them — discard is destructive and skipped when there is nothing to remove
  3. Check the path arguments; drop filters that exclude all modified files
  4. Re-run after any concurrent `but` command that may have changed the worktree

Example fix

// before: clean worktree
but discard 3a  // Error: No uncommitted changes to discard

// after: verify changes exist first
but               // shows uncommitted hunks
but discard 3a
Defensive patterns

Strategy: validation

Validate before calling

# confirm uncommitted changes exist first
but status || but  # verify uncommitted hunks are listed
[ -n "$(git status --porcelain)" ] || { echo "nothing to discard"; exit 0; }

Prevention

When it happens

Trigger: Running `but discard` on uncommitted changes when the worktree is clean; path filters that match no modified files; a prior operation (commit/absorb/discard) already consumed the changes between inspection and execution.

Common situations: Scripted discard after a previous command already committed or cleaned the worktree; discarding a path that is actually unmodified; stale terminal view where the user believes changes exist but they were committed via `but commit`.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/legacy/discard.rs:526

                match selection {
                    UncommittedSelection::All => builder.push_changes_from_uncommitted_area()?,
                    UncommittedSelection::Changes(changes) => {
                        for change in *changes {
                            match change {
                                UncommittedDiscardSource::HunkOrFile(change) => {
                                    builder.push_changes_from_uncommitted(&change)?;
                                }
                                UncommittedDiscardSource::PathPrefix(hunks) => {
                                    builder.push_changes_from_path_prefix(&hunks)?;
                                }
                            }
                        }
                    }
                }
                builder.reconcile_worktree_diff_specs()?;
                builder.into_diff_specs()
            };
            anyhow::ensure!(!changes.is_empty(), "No uncommitted changes to discard");
            let paths = paths_from_changes(&changes);
            ExecutableDiscardOperation::Uncommitted { paths, changes }
        }
    };

    let (mut outcome, mut ws) = but_transaction::with_transaction_with_perm(
        ctx,
        meta,
        perm,
        SnapshotDetails::new(oplog_operation_kind),
        DryRun::No,
        |mut tx| {
            let outcome = match executable {
                ExecutableDiscardOperation::Branches { branches, commits } => {
                    if !commits.is_empty() {
                        tx.discard_commits(commits.iter().map(|c| c.commit_id))?;
                    }
                    for branch in &branches {

View on GitHub (pinned to 58e5313667)