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
- Run `but` to confirm there are uncommitted changes before discarding
- Commit the changes (`but commit`) if you actually wanted to keep them — discard is destructive and skipped when there is nothing to remove
- Check the path arguments; drop filters that exclude all modified files
- 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
- Run `but` before discard to confirm dirty worktree
- Commit instead of discarding when changes should be kept
- Beware path filters that exclude all modified files
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
- No committed changes to discard
- `but setup` cannot run from a linked worktree; run it from…
- Cannot compute diff specs for worktree
- Cannot operate on uncommitted changes in worktree
- Could not discard all selected changes
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)