gitbutlerapp/gitbutler · error
Could not discard all selected changes
Error message
Could not discard all selected changes: {refused_paths} What it means
The `but discard` command attempted to discard the selected uncommitted changes, but some files were refused by the underlying git operation (typically because they are in conflict or cannot be discarded safely). The CLI reports the exact refused file paths via the `{refused_paths}` list joined with commas so the user knows which changes were left untouched.
Solutions
- Inspect the listed refused paths and resolve conflicts manually (e.g. `git checkout -- <path>` or `git restore <path>` once resolved)
- Re-run `but status` (or refresh the UI) so the change list matches the current worktree, then discard again
- Complete or abort the in-progress merge/rebase (`git merge --abort`) that puts the files in conflict state
- Discard the refused files one at a time to isolate which one is problematic
Example fix
// before: discard everything in one call, failing on any refusal
let outcome = discard(ctx, all_paths)?;
// after: discard individually and report per-path failures
for path in paths {
if let Err(e) = discard(ctx, vec![path.clone()]) {
eprintln!("could not discard {}: {e}", path);
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// resolve conflicts first
let conflicted: Vec<_> = repo.statuses(None)?.iter().filter(|e| e.status().is_conflicted()).collect();
if !conflicted.is_empty() {
bail!("resolve conflicts before discarding: {:?}", conflicted);
} Try / catch
match discard(ctx, paths) {
Err(e) if e.to_string().contains("Could not discard all selected changes") => {
let refused = extract_paths(&e.to_string());
eprintln!("resolve these files manually: {refused}");
}
Err(e) => return Err(e),
Ok(outcome) => outcome,
} Prevention
- Refresh the change list immediately before discarding to avoid stale paths
- Check for merge/rebase conflict state before offering discard
- Discard files in small batches so a single refusal doesn't block everything
When it happens
Trigger: Calling `discard()` on a selection of uncommitted changes where `git discard`/gix refuses at least one path — e.g. a file has unresolved merge conflict state, is newly staged/unstaged in a way the discard backend won't reverse, or the worktree state changed between listing and discarding.
Common situations: Users select all changes in a conflicted worktree and hit discard; IDE/CLI stale view after files changed on disk; discarding changes to files inside conflicted merge state; race between UI list refresh and the discard call.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- Aborting due to empty branch name
- Bare repositories are not supported.
- Branch ' ' not found
- Branch ' ' not found when checking for conflicts
- Branch " " has no conflicted commits.
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/4e0bd2405b0e1c00.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but/src/command/legacy/discard.rs:579
let new_commit = tx.discard_changes_from_commit(source.commit_id, changes)?;
DiscardOutcome::CommittedChanges {
source,
paths,
new_commit: new_commit.into(),
}
}
ExecutableDiscardOperation::Uncommitted { paths, changes } => {
let refused = but_workspace::discard_workspace_changes(
tx.repo(),
changes,
tx.context_lines(),
)?;
if !refused.is_empty() {
let refused_paths = refused
.iter()
.map(|change| change.path.as_bstr())
.join(", ");
bail!("Could not discard all selected changes: {refused_paths}");
}
DiscardOutcome::Uncommitted { paths }
}
};
Ok(Commit(outcome))
},
)?;
if let DiscardOutcome::Commits {
replaced_commits, ..
} = &mut outcome
{
*replaced_commits = std::mem::take(&mut ws.replaced_commits);
}
Ok((outcome, ws))
}View on GitHub (pinned to 58e5313667)