# Undo an unpublished Git commit while keeping its edits

Canonical: https://githtml.com/guides/git-undo-local-commit-keep-changes
Published: 2026-11-23
Publisher: WaveTech LLC / gitHtml

For an unpublished latest commit with a parent, git reset --soft HEAD~1 moves the current branch back while retaining the index and working files. Create a recovery reference and inspect the target first. This rewrites local branch history and is not the routine way to reverse a commit that collaborators already use.

## Check the recipe’s preconditions

This operation is for a local commit you want to reorganize, not a general method for rolling back a release. Verify that the commit has not been shared and that the desired target is its first parent. A root commit has no HEAD~1, and a merge’s parent choice deserves separate analysis. Stop if those conditions do not match your situation.

Soft reset leaves the index unchanged. If you already have staged changes beyond the last commit, they remain staged too, so the resulting proposed commit may combine several pieces of work. Inspect status and both diffs before resetting. A backup branch preserves the old commit, but it does not capture uncommitted edits by itself.

## Preserve the tip and move only the branch

Choose an unused recovery branch name. The show command verifies the target before reset. Afterward, inspect the staged diff, which now includes the difference between the retained index and the earlier HEAD. No hard-reset option belongs in this keep-the-edits workflow.

1. If you want the retained changes unstaged instead, understand mixed reset separately; it changes the index as well as moving the branch, though it retains working files.
2. Do not run a reset against a shared branch merely because it is easier than preparing a corrective commit. Use the project’s coordinated shared-history procedure.

````shell
git status --short
git log --oneline -3
git branch recovery/before-local-undo HEAD
git show --no-patch --oneline 'HEAD~1'
git reset --soft 'HEAD~1'
git diff --staged
````

## Rebuild a coherent commit

Review the retained content and choose the new commit boundary. You may amend wording, split independent changes, or add a missing test, but verify the staged snapshot before committing again. The old commit remains reachable through your recovery branch until you deliberately remove that reference.

If the goal was only changing a message, a carefully scoped amendment may be more direct; it still changes commit identity and has the same shared-history concerns. Keep the recovery point until the replacement is verified. Finish by comparing the new patch with the intended edits and confirming that unrelated working changes were neither lost nor accidentally included.

1. After a soft reset, compare the staged diff with the old commit preserved on the recovery branch. If extra changes appear, determine whether they were already staged before the reset. That explanation matters when splitting the original commit without accidentally combining a newer, unfinished correction.
2. If an unstaged edit modifies the same lines as the retained staged patch, preserve the distinction while rebuilding commits. The editor shows working-tree content, whereas the next commit records the index. Check the staged version explicitly before concluding that a visible correction will be included.

## Sources and further reading

- [Git reference: git-reset](https://git-scm.com/docs/git-reset)
- [Git reference: git-branch](https://git-scm.com/docs/git-branch)
- [Git reference: git-diff](https://git-scm.com/docs/git-diff)

## Related guides

- [Resolve “unmerged files” before continuing Git](https://githtml.com/guides/git-unmerged-files-resolve-conflict)
- [Handle untracked files that block checkout or merge](https://githtml.com/guides/git-untracked-files-would-be-overwritten)
- [Why a file in .gitignore still appears in Git changes](https://githtml.com/guides/gitignore-file-still-tracked)
- [Abort an unfinished Git merge carefully](https://githtml.com/guides/git-abort-merge-preserve-local-work)

Editorial approach: https://githtml.com/guides/about
