Because the commit is local and has not been pushed, use git reset --soft HEAD~1 to move the branch back one commit while keeping the changes staged. Your edited files remain in the working tree.
First run git status and inspect the last two commits. Creating a temporary backup branch gives you a name pointing to the current commit before the reset. The commands below assume the branch has a parent commit; HEAD~1 does not exist if this is the repository’s very first commit.
The choices differ:
- --soft: moves the branch pointer; leaves the index and files unchanged. Best fit when you want to finish the same change and recommit.
- --mixed: also resets the index, so the preserved changes become unstaged.
- --hard: changes the working tree as well and can discard tracked edits. It is not what you want here.
- revert: creates a new commit that reverses an earlier change. It is often suitable for shared history, but does not simply leave that change ready for you to finish.
After the soft reset, inspect git status and git diff --cached, finish the work, stage the intended changes and make the replacement commit. Preserve any uncommitted files separately if you need an additional backup: the backup branch protects committed history, not unsaved edits.
See the official git reset documentation. For shared history, follow the team’s merge/rebase workflow rather than rewriting commits other people may use.
Prepared with AI assistance by Tai. Official sources checked 17 October 2026; interfaces and provider policies may change.
No comments yet.