I would leave off the --soft in the other two answers and go with a simple git reset @^ (or git reset HEAD^ in older versions of git), which will default to git reset --mixed @^. The difference is that a soft reset leaves the files staged for commit, which is not what it sounds like you want to do. If you really want to undo the commit, you should also probably unstage the changes, which is what the default does. I find this much more useful in the general case than a soft reset, which is probably why mixed is the default.

Answer from Gary Fixler on Stack Overflow
Discussions

Can I delete (or undo) a git commit but keep the changes? - Stack Overflow
In one of my development branches, I made some changes to my codebase. Before I was able to complete the features I was working on, I had to switch my current branch to master to demo some features... More on stackoverflow.com
🌐 stackoverflow.com
New to git, advice needed. Revert commit but keep changes
You can either reset, as u/large_crimson_canine suggested, or you can make your new changes, git add them and then amend the commit you already made with: git --amend or, to retain the previous commit message: git --amend --no-edit More on reddit.com
🌐 r/git
17
0
November 18, 2023
How do I undo the most recent local commits in Git? [Tutorial]
git reset**:** This allows you to move the HEAD to a specific state, effectively undoing commits while keeping your changes staged or unstaged. Just remember to use it carefully, as it can alter your commit history. git restore**:** this provides a simpler way to undo changes in the working directory and staging area introduced by the most recent commit. It's a handy tool for reverting changes quickly. git revert**:** If you've already pushed your commits to a remote repository and want to undo them without altering history, git revert is a safe option. It creates a new commit that undoes the changes made in a specified commit. git checkout**:** While primarily used to switch branches, git checkout can also help you undo local commits by moving the HEAD pointer to a previous commit. It's useful for discarding the most recent commit. git commit --amend**:** If you only need to modify the commit message of your most recent commit, this command comes in handy. It allows you to edit the commit message without creating a new commit. Or the solution I've adopted a while ago and never looked back, lol, is cmd+z from Tower , their undo command is pure magic. More on reddit.com
🌐 r/git
3
0
May 1, 2024
Reverting changes to a single file - why are so simple things so difficult?
It seems difficult at first, when you think of it in terms of "versioning files". But git is built around the idea of versioning the whole project, not individual files. This gives you a few options to revert a single file: 1. The file hasn't changed since the commit you want to revert for the file. In this case you can do git checkout COMMIT FILENAME and then commit the change. 2. The file has received further edits. You want the behavior of revert but only for one file. Easiest thing I can think of: git revert --no-commit COMMIT. Now all changes from that commit are reverted in the working tree and staged. git reset to unstage all the changes. git commit FILENAME... to commit only the reversial of specific files. git reset --hard to undo the remaining changes on the working tree. More on reddit.com
🌐 r/git
10
13
March 17, 2023
People also ask

How do I undo the last commit but keep the changes?
Run git reset --soft HEAD~1. This removes the last commit but leaves its changes staged, so you can re-commit them right away. For the changes to sit unstaged in your working tree instead, use git reset HEAD~1 (the default mode).
🌐
coddy.tech
coddy.tech › git commands › undoing changes › git undo last commit
Git Undo Last Commit - Keep or Discard Changes | Coddy
How do I undo the last commit and keep changes unstaged?
Run git reset HEAD~1 (same as git reset --mixed HEAD~1). This removes the commit and keeps file changes in your working tree, unstaged.
🌐
devtoolbox.dedyn.io
devtoolbox.dedyn.io › home › blog › undo last commit in git
How to Undo Last Commit in Git (Keep, Unstage, or Discard Changes) ...
How do I undo the last commit and delete the changes?
Run git reset --hard HEAD~1. This removes the commit and discards its changes from your working tree. It's destructive - if you might need the work, use --soft instead, or recover later via git reflog.
🌐
coddy.tech
coddy.tech › git commands › undoing changes › git undo last commit
Git Undo Last Commit - Keep or Discard Changes | Coddy
🌐
Aviator
aviator.co › home › blog › how to git undo commit: methods and best practices
How to Git Undo Commit: Methods and Best Practices - Aviator Blog
February 10, 2025 - To unstage a file after git add, ... already committed and want to undo it while keeping the changes staged, use git reset –soft HEAD~1....
🌐
KodeKloud
kodekloud.com › blog › git-uncommit-last-commit
How to Uncommit Last commit in Git (5 Scenarios)
November 25, 2025 - The answer is simple: use the git reset --soft HEAD~1 command. This command will undo your last commit, but it will keep your changes and your staging intact. It will move the HEAD pointer (which points to the latest commit on your current branch) ...
🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
You can undo local changes that are already staged. In the following example, a file was added to the staging, but not committed: ... On branch main Your branch is up-to-date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: <file>
🌐
Git
git-scm.com › book › en › v2 › Git-Basics-Undoing-Things
2.4 Git Basics - Undoing Things
If you want to redo that commit, make the additional changes you forgot, stage them, and commit again using the --amend option: ... This command takes your staging area and uses it for the commit. If you’ve made no changes since your last commit (for instance, you run this command immediately ...
Find elsewhere
🌐
JanBask Training
janbasktraining.com › community › devops › how-do-i-undo-the-most-recent-local-commits-in-git
How do I undo the most recent local commits in Git? | JanBask Training Community
March 18, 2025 - You can undo the last commit in Git using git reset. Use --soft to keep changes staged, --mixed to unstage them, or --hard to discard them completely.
🌐
DevToolbox
devtoolbox.dedyn.io › home › blog › undo last commit in git
How to Undo Last Commit in Git (Keep, Unstage, or Discard Changes) | DevToolbox Blog
February 26, 2026 - This 60-second preflight makes the right command choice obvious: --soft when you want to keep staged edits, --mixed when you want to re-stage selectively, and revert when branch history is already shared.
🌐
Medium
medium.com › @sivaraaj › how-to-undo-the-most-recent-local-commits-in-git-7892fd717964
How to Undo the Most Recent Local Commits in Git ? | by Sivaraj Ramasamy | Medium
February 18, 2024 - $ git status On branch main Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: file1.txt modified: file2.txt $ git reset HEAD Unstaged changes after reset: M file1.txt M file2.txt $ git status On branch main ...
🌐
Coddy.Tech
coddy.tech › git commands › undoing changes › git undo last commit
Git Undo Last Commit - Keep or Discard Changes | Coddy
3 weeks ago - Use git commit --amend. It reopens the last commit so you can edit its message (and re-stage files if needed) without creating a separate commit. Avoid amending a commit you've already pushed, since it rewrites history.
🌐
Git Tower
git-tower.com › learn › git faq › how to undo, revert, or delete a git commit
How to Undo, Revert, or Delete a Git Commit | Learn Version Control with Git
The --soft flag preserves your changes as staged modifications, so you can adjust them and recommit. If you'd prefer to unstage the changes but keep them in your working directory, omit the flag (the default is --mixed):
Published   6 days ago
🌐
LabEx
labex.io › tutorials › git-how-to-undo-git-commit-but-keep-changes-392512
How to Undo Git Commit But Keep Changes | LabEx
... The default mode for git reset is the --mixed option, which moves the branch pointer to the specified commit and also unstages any changes that were staged for the next commit.
🌐
Quora
quora.com › How-do-you-undo-a-git-commit-without-losing-your-files
How to undo a git commit without losing your files - Quora
To keep file changes but remove ... (keeps staged) or git reset --mixed (keeps unstaged). Avoid --hard unless you want to discard working-tree changes. ... These commands preserve your file contents except when using --hard; choose the option that matches whether the commit has been shared. ... That's it, your commit changes will be in your working directory, whereas the LAST commit will ...
Top answer
1 of 14
3396

It's as simple as this:

git reset HEAD^

Note: some shells treat ^ as a special character (for example some Windows shells or ZSH with globbing enabled), so you may have to quote "HEAD^" or use HEAD~1 in those cases.

git reset without a --hard or --soft moves your HEAD to point to the specified commit, without changing any files. HEAD^ refers to the (first) parent commit of your current commit, which in your case is the commit before the temporary one.

Note that another option is to carry on as normal, and then at the next commit point instead run:

git commit --amend [-m … etc]

which will instead edit the most recent commit, having the same effect as above.

Note that this (as with nearly every git answer) can cause problems if you've already pushed the bad commit to a place where someone else may have pulled it from. Try to avoid that

2 of 14
430

There are two ways of handling this. Which is easier depends on your situation.

Reset

If the commit you want to get rid of was the last commit, and you have not done any additional work you can simply use git-reset

git reset HEAD^

Takes your branch back to the commit just before your current HEAD. However, it doesn't actually change the files in your working tree. As a result, the changes that were in that commit show up as modified - its like an 'uncommit' command. In fact, I have an alias to do just that.

git config --global alias.uncommit 'reset HEAD^'

Then you can just used git uncommit in the future to back up one commit.

Squashing

Squashing a commit means combining two or more commits into one. I do this quite often. In your case you have a half done feature commited, and then you would finish it off and commit again with the proper, permanent commit message.

git rebase -i <ref>

I say above because I want to make it clear this could be any number of commits back. Run git log and find the commit you want to get rid of, copy its SHA1 and use it in place of <ref>. Git will take you into interactive rebase mode. It will show all the commits between your current state and whatever you put in place of <ref>. So if <ref> is 10 commits ago, it will show you all 10 commits.

In front of each commit, it will have the word pick. Find the commit you want to get rid of and change it from pick to fixup or squash. Using fixup simply discards that commits message and merges the changes into its immediate predecessor in the list. The squash keyword does the same thing, but allows you to edit the commit message of the newly combined commit.

Note that the commits will be re-committed in the order they show up on the list when you exit the editor. So if you made a temporary commit, then did other work on the same branch, and completed the feature in a later commit, then using rebase would allow you to re-sort the commits and squash them.

WARNING:

Rebasing modifies history - DONT do this to any commits you have already shared with other developers.

Stashing

In the future, to avoid this problem consider using git stash to temporarily store uncommitted work.

git stash save 'some message'

This will store your current changes off to the side in your stash list. Above is the most explicit version of the stash command, allowing for a comment to describe what you are stashing. You can also simply run git stash and nothing else, but no message will be stored.

You can browse your stash list with...

git stash list

This will show you all your stashes, what branches they were done on, and the message and at the beginning of each line, and identifier for that stash which looks like this stash@{#} where # is its position in the array of stashes.

To restore a stash (which can be done on any branch, regardless of where the stash was originally created) you simply run...

git stash apply stash@{#}

Again, there # is the position in the array of stashes. If the stash you want to restore is in the 0 position - that is, if it was the most recent stash. Then you can just run the command without specifying the stash position, git will assume you mean the last one: git stash apply.

So, for example, if I find myself working on the wrong branch - I may run the following sequence of commands.

git stash
git checkout <correct_branch>
git stash apply

In your case you moved around branches a bit more, but the same idea still applies.

🌐
codestudy
codestudy.net › blog › how-to-undo-the-last-commit-in-git-but-keep-my-changes-as-unstaged
How to Undo the Last Git Commit and Keep Changes Unstaged: A Step-by-Step Guide — codestudy.net
Moves the branch pointer (e.g., main) back to HEAD~1 (undoing the last commit). Resets the staging area (index) to match the new HEAD, so changes from the undone commit are unstaged.
🌐
Microsoft Learn
learn.microsoft.com › en-us › azure › devops › repos › git › undo
Undo changes in your Git repo - Azure Repos | Microsoft Learn
The --soft flag tells Git to reset the branch to the specified commit, but to keep all subsequent changes as staged and unstaged changes per their previous state. A common use of Git reset is with the --hard option to discard all uncommitted ...
🌐
Continuously Merging
articles.mergify.com › git-undo-commit-keep-changes
Git Undo Commit Keep Changes A Practical Guide
September 21, 2025 - You decide it makes more sense to merge these into one clean commit. No problem. You can undo those last three commits while keeping all the code changes staged and ready for a new commit. To pull this off, you just run: git reset --soft HEAD~3
🌐
GitHub
github.com › orgs › community › discussions › 183621
undo the last commit · community · Discussion #183621
You can use git reset with the --soft or --mixed option to undo the last commit while keeping your changes. ... HEAD~1 refers to the commit before the last one. The changes remain in the staging area, ready to amend or create a new commit.
🌐
DataCamp
datacamp.com › blog › git-undo-last-commit
Git Undo Last Commit: Step-by-Step Guide for Beginners | DataCamp
June 23, 2025 - Yes, use git reset --soft to keep your changes staged or --mixed to keep them in your working directory. Use git revert. It preserves history by creating a new commit that reverses the changes, avoiding conflicts with teammates. Use git log to list previous commits.
🌐
Jessica Temporal
jtemporal.com › undoing-the-last-commit-and-reusing-the-message
Undoing the last commit and keeping the changes for a next commit | Jessica Temporal
June 20, 2026 - Now it’s time to undo our wrong commit. Given this scenario, the first step is to use the command git reset. Maybe you don’t know that there is a flag that while undoing a commit with git reset, it allows you to keep the commit changes on ...