From eb4346fce2ef217ddebc5dff754964aa354c2b15 Mon Sep 17 00:00:00 2001 From: Christoph Brandau Date: Fri, 11 Sep 2026 11:51:33 +0200 Subject: [PATCH] feat(git): use soft reset to keep changes staged on undo Change undo-last-commit behavior to perform a soft reset instead of a mixed reset. This preserves the index and working tree so the undone commit's changes remain staged and ready to recommit. The confirmation dialog text was updated to accurately reflect the new behavior. - Perform git reset --soft HEAD~1 to move HEAD while preserving index - Update UI confirmation copy to state that changes remain staged and files are preserved --- src-tauri/src/git.rs | 7 +++---- src/App.svelte | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/git.rs b/src-tauri/src/git.rs index fe3ee72..29f1428 100644 --- a/src-tauri/src/git.rs +++ b/src-tauri/src/git.rs @@ -2615,10 +2615,9 @@ pub fn undo_last_commit(path: String) -> Result { return Err("This is the first commit; there is nothing to undo to.".to_string()); } - // Mixed reset: moves HEAD back one commit and unstages the difference, but - // leaves the working tree files untouched, so the undone commit's changes - // reappear as ordinary uncommitted changes instead of being discarded. - run_git(&repo, ["reset", "HEAD~1"])?; + // Soft reset: moves HEAD back one commit while preserving the index and + // working tree, so the undone commit's changes remain staged. + run_git(&repo, ["reset", "--soft", "HEAD~1"])?; status_for_repo(&repo) } diff --git a/src/App.svelte b/src/App.svelte index 4066aa5..067eef3 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -4719,7 +4719,7 @@ async function undoLastCommitChange() { if (!activeRepoPath || !canAmend || isBusy) return; const confirmed = window.confirm( - "Undo the last commit?\n\nIts changes come back as uncommitted changes in the working tree — nothing is discarded.", + "Undo the last commit?\n\nIts changes remain staged, ready to commit again. Your working tree files are preserved.", ); if (!confirmed) return;