With git reflog check which commit is one prior the merge (git reflog will be a better option than git log). Then you can reset it using:

git reset --hard commit_sha

There's also another way:

git reset --hard HEAD~1

It will get you back 1 commit.

Be aware that any modified and uncommitted/unstashed files will be reset to their unmodified state. To keep them either stash changes away or see --merge option below.


As @Velmont suggested below in his answer, in this direct case using:

git reset --hard ORIG_HEAD

might yield better results, as it should preserve your changes. ORIG_HEAD will point to a commit directly before merge has occurred, so you don't have to hunt for it yourself.


A further tip is to use the --merge switch instead of --hard since it doesn't reset files unnecessarily:

git reset --merge ORIG_HEAD

--merge

Resets the index and updates the files in the working tree that are different between <commit> and HEAD, but keeps those which are different between the index and working tree (i.e. which have changes which have not been added).

Answer from Marcin Gil on Stack Overflow
🌐
DataCamp
datacamp.com › tutorial › git-revert-merge
Git Revert Merge Commit: A Guide With Examples | DataCamp
November 5, 2024 - Yes, that's the main use case for git revert on merges. If the changes are local then git reset is an easier way to undo the merge.
Discussions

How to undo a merge
You can ise revert to undo a commit: https://git-scm.com/docs/git-revert More on reddit.com
🌐 r/git
6
3
October 13, 2021
Why am I unable to undo a git merge [PyCharm]?
PyCharm's git management is useful, convenient, but quite limited. I'd suggest that you close PyCharm temporarily, revert the problem commit using either the command line or your preferred git management tool. Then force update your local version. When you re-open PyCharm, it should automatically pick up the changes. More on reddit.com
🌐 r/learnpython
8
1
January 10, 2024
Remove all changes merged from a specific branch
The git revert command is able to revert a merge, but you won't be able to merge those commits again. I guess it may work if you rebase the commits you are interested in on the feature branch or create a new feature branch and cherry-pick the commits. Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. More on reddit.com
🌐 r/git
13
1
July 18, 2024
How to undo pushed commits
Yes, it's called a force push. Reset your local branch to the commit you want. Assuming you have main checked out: git reset --hard COMMIT_ID with COMMIT_ID being any ref you want, either a commit id, origin/main^^, etc. Then force push the branch: git push -f origin main To ensure no one else has pushed work on top of main in the meantime, you should use --force-with-lease. git push --force-with-lease origin main (edit): In your case you will probably want to cherry-pick the last commit on the mainline on top of that, unless that's solely related to the commit you want to remove. (edit2): Final note: if you want to avoid people pushing crap you don't want in your mainline, start doing pull requests and deny those people access to your mainline. (edit3): Forgot to mention that you'll have to instruct your coworkers to reset their work too. In this case I'd instruct them to create a separate branch and start a PR with their work, so you (both) have the opportunity to clean things up within that branch before merging to mainline. That avoids them losing their work and/or screwing up their local working tree. More on reddit.com
🌐 r/git
8
5
January 29, 2024
People also ask

How to undo a merge in Git
If a merge is still in progress (conflicts are unresolved), you can abort it cleanly with git merge --abort, which restores your branch to the exact state it was in before the merge started. If the merge has already been committed locally but not yet pushed, roll it back with git reset --hard ORIG_HEAD — Git automatically sets ORIG_HEAD to the pre-merge commit, making it the perfect rollback target. For a merge commit that has already been pushed to a shared remote, the safe approach is git revert -m 1 , which creates a new commit that reverses the merge without rewriting history, so no force-
🌐
git-tower.com
git-tower.com › learn › git faq › how to undo a merge in git
How to undo a merge in Git | Learn Version Control with Git
Are there any other methods to undo a merge in Git?
You can also use git rebase or git checkout to undo a merge in Git. With git rebase, you can roll back to a specific commit by using its SHA (which is the unique identifier for the commit). This essentially moves your project’s history to a point before the merge, allowing you to rebuild from there. Another option is git checkout, where you can check out an earlier commit and create a new branch from that point, which bypasses the merge altogether.
🌐
wikihow.com
wikihow.com › computers and electronics › software › software testing › how to undo a merge in git: 2 simple step-by-step methods
How to Undo a Merge in Git: 2 Simple Step-by-Step Methods
🌐
Git Tower
git-tower.com › learn › git faq › how to undo a merge in git
How to undo a merge in Git | Learn Version Control with Git
1 day ago - With the "git reset" command: for merges that have only occurred in your local repository. With the "git revert" command: for those situations where the merge has already been pushed to the remote repository.
🌐
Better Stack
betterstack.com › community › questions › how-to-revert-merge-commit-that-has-already-been-pushed-to-remote
How Do I Revert a Merge Commit That Has Already Been Pushed to Remote? | Better Stack Community
Next, revert the merge commit locally on your machine: ... Replace <merge-commit-hash> with the hash of the merge commit you identified. The -m 1 option specifies that you want to revert to the parent of the merge commit on the mainline (typically ...
🌐
Wikihow
wikihow.com › computers and electronics › software › software testing › how to undo a merge in git: 2 simple step-by-step methods
How to Undo a Merge in Git: 2 Simple Step-by-Step Methods
December 11, 2025 - Using git revert is a better option ... undoes the changes. You can use git revert with a local merge as well, but git reset may be beneficial because you don't necessarily need to know the commit hash....
🌐
freeCodeCamp
freecodecamp.org › news › git-undo-merge-how-to-revert-the-last-merge-commit-in-git
Git Undo Merge – How to Revert the Last Merge Commit in Git
March 30, 2022 - If you are not sure of the hash of the last commit, you can run git reset --hard HEAD~1 to go back to the commit before the merge: Note that when you use the --hard flag to undo a merge, any uncommitted change will be reverted.
Find elsewhere
🌐
Alphr
alphr.com › home › how to revert a merge in git
How to Revert a Merge in Git
January 3, 2024 - Enter git revert followed by -m 1. Use the git push command to undo the merge commit locally.
🌐
Better Stack
betterstack.com › community › questions › how-to-undo-unpushed-git-merge
Undo a Git Merge That Hasn’t Been Pushed Yet? | Better Stack Community
June 24, 2024 - To force git pull to overwrite local files, you can use the git reset command along with the --hard option after pulling changes.
🌐
Graphite
graphite.com › guides › how-to-undo-a-git-merge
How to undo a git merge - Graphite
From here you can run git stash pop to recover these changes, and apply them directly on top of your local state. Undoing a merge that has already been pushed to the remote repository is more complex because it affects the repository history that others might have based their work on. One approach is to revert the merge commit using git revert:
🌐
How-To Geek
howtogeek.com › home › programming › how to reverse a git merge
How To Reverse a Git Merge
July 11, 2023 - You don't want to ever "delete" commits, and git merges are added as "merge commits." You'll want to use git revert to safely undo the changes, and commit that undoing as a new commit. However, if you just messed something up locally, cursed at your keyboard, and Googled for a solution, you can still safely delete the merge commit and keep your Git history clean with a simple git reset.
🌐
Continuously Merging
articles.mergify.com › how-to-undo-a-merge-in-git
How to Undo a Merge in Git
June 8, 2023 - Even better, once changes have been made, you can revert the revert itself by referencing its id in git revert <sha-of-revert>. All those operations create a new commit that you can push to your remote, as needed. Undoing a merge you just made in your local environment is one of the easier operations of this type that you can perform.
🌐
Warp
warp.dev › terminus by warp › git › undo a git merge
How To Undo Merged Commits in Git Using git-reset And git-revert | Warp
June 27, 2024 - Learn how to change the remote url of a local git-enabled directory using the git-remote command and Warp's workflow feature. ... $ git log --oneline 42d4df9 (HEAD -> master) add server post endpoint b575a79 create server $ git revert -m 1 42d4df9 [master c21acf3] Revert "add server post endpoint" 1 file changed, 5 deletions(-) $ git log --oneline c21acf3 (HEAD -> master) Revert "add server post endpoint" 42d4df9 add server post endpoint b575a79 create server
🌐
CoreUI
coreui.io › answers › how-to-undo-git-merge
How to undo git merge · CoreUI
January 15, 2026 - # Before undoing, check what changed ... merge --abort during conflicts to cancel in-progress merges. Use git reset --hard HEAD~1 to undo local merges before pushing....
🌐
Michael Uloth
michaeluloth.com › git-undo-merge-to-main
Undoing a merge to your main git branch • Michael Uloth
December 17, 2025 - Click the “Revert” button at the bottom of the reversion PR you just merged to create a new revert-revert- branch that includes the same changes as your original feature branch (i.e. revert the reversion) Pull that revert-revert- branch locally ...
🌐
Sentry
sentry.io › sentry answers › git › undo an unpushed git merge
Undo an unpushed Git merge | Sentry
In a local repository, I have accidentally merged two branches. How do I undo this? I have not yet pushed the changes. If the merge has not yet been committed – i.e. git merge was not run with the --commit flag and git commit has not been run since the merge – then we can abort the merge with the following command:
🌐
Stack Abuse
stackabuse.com › git-revert-a-merge
Git: Revert a Merge
June 11, 2019 - $ git reflog 8135d07 HEAD@{0}: commit (merge): Merge branch local/bug-34 into local/master 03979c8 HEAD@{1}: commit: Added support for query params 9f7a993 HEAD@{2}: commit (initial): Initial commit · Once you find the commit that you want to revert back to, use the reset command, similar to what we did when reverting to a previous commit, which is essentially what we're doing here:
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-revert-the-last-merge-commit-in-git
How To Revert The Last Merge Commit in Git? - GeeksforGeeks
June 21, 2024 - Reverting the last merge commit in Git can be done using either git revert or git reset, depending on your needs. Git revert is generally safer and preferred for shared repositories, while git reset is useful for local changes and rewriting history.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how do you undo a git merge?
How do you undo a Git merge? | Solutions to Git Problems
February 7, 2025 - You will then select Reset <branch ... changes you want to undo to your remote repository, right-click on the merge commit and select Revert commit from the context menu....
🌐
Reddit
reddit.com › r/git › how to undo a merge
r/git on Reddit: How to undo a merge
October 13, 2021 -

Hello I merged my branch (abc-branch) into a test branch and now When I check the abc-branch I see that it's "polluted" by the test branch .

Is it possible to undo that merge and make that branch like before?

🌐
GeeksforGeeks
geeksforgeeks.org › git › github-undo-merge
Github Undo Merge - GeeksforGeeks
October 10, 2024 - The command allows you to undo a local merge by resetting your branch to the commit right before the merge. This method is destructive, meaning that any changes made by the merge and commits after it will be lost.