You are trying to revert a merge commit, and git doesn't know which parent to revert to. The -m allows us to choose which parent to choose. See the merge commit and note down which parent you want to go to. The parent information can be seen in git log, for example:

commit d02ee0f2179def10277f30c71c5d6f59ded3c595

Merge: dd3a24c 2462a52

and run:

git revert <hash> -m 1

where 1 indicates parent number 1 (dd3a24c).

If you are trying to revert to that commit, do:

git reset --hard <hash>

Understand the difference between git revert and git reset from the docs and decide which one you want. git revert is the safer option, but doesn't really do what you want. It just reverts the changes of a (set of) commit. git reset makes you move to a particular commit in history, and will rewrite your history.

Answer from manojlds on Stack Overflow
Top answer
1 of 2
79

You are trying to revert a merge commit, and git doesn't know which parent to revert to. The -m allows us to choose which parent to choose. See the merge commit and note down which parent you want to go to. The parent information can be seen in git log, for example:

commit d02ee0f2179def10277f30c71c5d6f59ded3c595

Merge: dd3a24c 2462a52

and run:

git revert <hash> -m 1

where 1 indicates parent number 1 (dd3a24c).

If you are trying to revert to that commit, do:

git reset --hard <hash>

Understand the difference between git revert and git reset from the docs and decide which one you want. git revert is the safer option, but doesn't really do what you want. It just reverts the changes of a (set of) commit. git reset makes you move to a particular commit in history, and will rewrite your history.

2 of 2
5

I want to revert back to ...

Then you don't want git revert, at least not like this. git revert is for reverting the specific changes made in that commit. What you're looking for is to revert or undo all the changes made after that commit.

git reset is the command to use here.

git reset --hard c14609d74eec3ccebafc73fa875ec58445471765 completely resets your branch, index and work tree to that specific commit.

Note that the usual precautions apply: if anyone else has fetched later commits already, removing them from the history like this complicates matters for them. If you instead want to create a new commit, which simply restores the state to that of commit c14609d74eec3ccebafc73fa875ec58445471765, you can use git rm and git checkout:

git rm -r .
git checkout c14609d74eec3ccebafc73fa875ec58445471765 .

(The rm is needed to make sure newly added files also get removed.) This lets you then create a new commit, on top of your local history, which undoes every change since c14609d74eec3ccebafc73fa875ec58445471765.

๐ŸŒ
Jannik Wempe
wempe.dev โ€บ home โ€บ blog โ€บ you have fucked up! how to git revert?
You Have Fucked Up! How to git revert? | Jannik Wempe
January 25, 2023 - What is the -m option of git revert? ... Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows ...
Discussions

github - Why does git revert complain about a missing -m option? - Stack Overflow
I'm working on a project with other people, and there are multiple GitHub forks being worked on. Someone just made a fix for a problem and I merged with his fork, but then I realized that I could f... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Cannot revert merge commit
Description In the commit graph, right click on a merge commit and click "Revert Commit..." GitLens Version 17.0.0 VS Code Version Version: 1.99.0 (system setup) Commit: 4437686ffebaf200f... More on github.com
๐ŸŒ github.com
1
April 7, 2025
github - Git Revert a Revert for a Merge - Stack Overflow
The error was indeed because of the conflicts. Although github does not really give much information. ... if you encounter the error 'commit hash is a merge but no -m option was given' then you perform the revert on the original commit and not the commit created on merge of your revert PR. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Need help undoing or fixing Merge commit and Revert merge commit that were both pushed to remote and merged into a parent branch
You currently have problems at three different layers: The contents at the tip of the develop branch aren't what people expect. If the revert of the merge commit caused the issue, reverting that revert should undo that specific change. I would suggest setting up CI to block commits that break functionality. Your company/team doesn't have policies or guidelines in place for how to deal with the various branches. There isn't a single correct way to do it so it'll come down to specific culture and tech stack needs. "gitflow" may be a good starting point as it's aligned with what's written in the description. There isn't tooling in place to enforce the branch merge strategy. This allows variations to be introduced that don't follow the standard pattern. These variations will either live in the git history forever or require rolling back the branches via force pushing. Going forward, when doing a review, I would suggest looking at the commits being merged and not just the file content diff. If the entire branch history isn't what is expected it can be a useful red flag. More on reddit.com
๐ŸŒ r/git
1
2
February 16, 2024
๐ŸŒ
DEV Community
dev.to โ€บ gabeguz โ€บ git-revert-merge-commits-confusion
Git Revert Merge: git revert, merge commits, confusion - DEV Community
September 8, 2017 - If I look at the merge commit (git show 5a) there's a line that says: parents 2, c. In my simple example, I think the mainline is 2, so I think I want to do git revert -m 1 (since 2 is the first of the parents listed) since commit 2 is on master, which I think is equivalent to mainline, but I'm not really sure.
Top answer
1 of 4
397

By default git revert refuses to revert a merge commit as what that actually means is ambiguous. I presume that your HEAD is in fact a merge commit.

If you want to revert the merge commit, you have to specify which parent of the merge you want to consider to be the main trunk, i.e. what you want to revert to.

Often this will be parent number one, for example if you were on master and did git merge unwanted and then decided to revert the merge of unwanted. The first parent would be your pre-merge master branch and the second parent would be the tip of unwanted.

In this case you could do:

git revert -m 1 HEAD

git cat-file -p [MERGE_COMMIT_ID] will show the parent branches in order. The first one listed would be -m 1, the second -m 2.

2 of 4
62

Say the other guy created bar on top of foo, but you created baz in the meantime and then merged, giving a history of

$ git lola
*   2582152 (HEAD, master) Merge branch 'otherguy'
|\  
| * c7256de (otherguy) bar
* | b7e7176 baz
|/  
* 9968f79 foo

Note: git lola is a non-standard but useful alias.

No dice with git revert:

$ git revert HEAD
fatal: Commit 2582152... is a merge but no -m option was given.

Charles Bailey gave an excellent answer as usual. Using git revert as in

$ git revert --no-edit -m 1 HEAD
[master e900aad] Revert "Merge branch 'otherguy'"
 0 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 bar

effectively deletes bar and produces a history of

$ git lola
* e900aad (HEAD, master) Revert "Merge branch 'otherguy'"
*   2582152 Merge branch 'otherguy'
|\  
| * c7256de (otherguy) bar
* | b7e7176 baz
|/  
* 9968f79 foo

But I suspect you want to throw away the merge commit:

$ git reset --hard HEAD^
HEAD is now at b7e7176 baz

$ git lola
* b7e7176 (HEAD, master) baz
| * c7256de (otherguy) bar
|/  
* 9968f79 foo

As documented in the git rev-parse manual

<rev>^, e.g. HEAD^, v1.5.1^0
A suffix ^ to a revision parameter means the first parent of that commit object. ^<n> means the n-th parent (i.e. <rev>^ is equivalent to <rev>^1). As a special rule, <rev>^0 means the commit itself and is used when <rev> is the object name of a tag object that refers to a commit object.

so before invoking git reset, HEAD^ (or HEAD^1) was b7e7176 and HEAD^2 was c7256de, i.e., respectively the first and second parents of the merge commit.

Be careful with git reset --hard because it can destroy work.

๐ŸŒ
RisingStack
blog.risingstack.com โ€บ home โ€บ hรญrek, esemรฉnyek โ€บ git catastrophes and tips to avoid them
Git Catastrophes and Tips to Avoid Them - RisingStack Engineering
July 4, 2024 - To deal with this, we need to call git revert -m 1 32f2e08, where -m 1 specifies the parent number of the branch to take, but if you try to use this with a range of commits, git will assume that the first commit in the range is the merge commit.
๐ŸŒ
GitHub
github.com โ€บ gitkraken โ€บ vscode-gitlens โ€บ issues โ€บ 4206
Cannot revert merge commit ยท Issue #4206 ยท gitkraken/vscode-gitlens
April 7, 2025 - > & "c:/Program Files/Git/cmd/git.exe" -C "c:/path/to/repo" -c "core.editor=c:/Program\ Files/Microsoft\ VS\ Code/bin/code --wait --reuse-window" revert --no-edit 34f246afb3c15153b1e598cc225f3a9b25bff8e4 error: commit 34f246afb3c15153b1e598cc225f3a9b25bff8e4 is a merge but no -m option was given.
Author ย  gitkraken
๐ŸŒ
Atlassian
jira.atlassian.com โ€บ browse โ€บ SRCTREE-2034
Reverting merge commits give an error | Sourcetree For Mac
Trying to revert a merge commit appears to require extra flags. I get the below error. error: Commit 9630e8dcb8f2a1cc656097f8cce35e2c1a268dda is a merge but no -m option was given.
Find elsewhere
๐ŸŒ
Reddit
reddit.com โ€บ r/git โ€บ need help undoing or fixing merge commit and revert merge commit that were both pushed to remote and merged into a parent branch
r/git on Reddit: Need help undoing or fixing Merge commit and Revert merge commit that were both pushed to remote and merged into a parent branch
February 16, 2024 -

Hi all, I am working off of 2 main branches: develop and prototype. Develop is our main stable branch where we create release branches from. Prototype is the main branch for our new epic we are developing.

EDIT: prototype is branched off of develop

I created a feature branch off of prototype called "submit-feature" and implemented some functionality.

I realized that submit-feature was behind develop and prototype by multiple commits. Locally, I decided to merge develop into prototype, and then merge prototype into submit-feature. I pushed this commit to remote.

When I created a pull request, I noticed that the changes from develop were being introduced into prototype from the submit-feature branch. There were too many files that were mixed with my changes, so I wanted to separate the merge from develop into prototype and isolate those changes and merge conflicts.

I reverted the merge commit, pushed that to remote, and updated my PR from submit-feature into prototype. Now, the PR only contains the file changes I made for the feature.

I merged develop into prototype separately and committed it. Prototype is now up-to-date, but I forgot to merge prototype into submit-feature. I merged my PR for submit-feature into prototype, but I didn't realize that there were deleted/changed files as a result of my previous merge commit. Develop is still clean since we won't merge prototype into it until we have completely tested everything.

Now prototype is broken and other devs have merged this branch with their feature branches. How can I undo this revert merge commit (and maybe the first merge commit) from my submit-feature and prototype branches?

Can I revert the "revert merge commit"? Should I pull develop and prototype again into submit-feature, and create another PR so it won't erase/mess with the commit history for the other devs?

What merging practices and steps should I follow in the future to avoid this situation? Any advice/suggestions would be appreciated, thanks!

๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 58310572
Git Issue: is a merge but no -m option was given - Stack Overflow
Where did you get the hash from? The revert error indicates that the hash ID is the hash ID of a merge commit. You can view the log message of the commit itself, and see a combined diff of the merge, with git show <hash>.
๐ŸŒ
lifewaza
lifewaza.com โ€บ posts โ€บ git-revert-merge-commits-confusion
git revert, merge commits, confusion ยท lifewaza
July 27, 2020 - I pulled up the git revert docs ... paraphrase of the docs, hereโ€™s the actual relevant section: Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline....
๐ŸŒ
Reddit
reddit.com โ€บ r/git โ€บ how to undo accidental merge in git history
r/git on Reddit: How to undo accidental merge in git history
April 5, 2023 -

I have a repo that I would like to fix the history of. In the process of trying to rebase my branches I accidentally created a merge commit with duplicated commits and then kept committing on top of this without realizing. How can I go back and rewrite my history to remove this accidental merge? Below is the current structure of my branch. I am trying to remove D' and E' since they are already existing in the 'proper' history as well as F because it is just a merge commit.

<many more commits to HEAD>
G
F
| \
|  E'
|  D'
|  |
E  |
D  |
C  |
B /
A

and Id like to change it to:

<many more commits to HEAD>
G
E
D
C
B
A
๐ŸŒ
Brainly
brainly.com โ€บ computers and technology โ€บ high school โ€บ what should you do if 'git revert' is a merge but no option was given?
[FREE] What should you do if 'git revert' is a merge but no option was given? - brainly.com
November 19, 2023 - If you have used git revert and encountered a message indicating "a merge but no option was given," it means you attempted to revert a merge commit without specifying how the revert should be handled.
๐ŸŒ
SysTutorials
systutorials.com โ€บ how-to-revert-a-merge-in-git
How To Revert A Git Merge - SysTutorials
April 12, 2026 - The -m 1 flag tells Git which parent of the merge commit to revert to (the first parent is typically your main branch). Find the merge commit hash with: ... This creates a new commit that undoes the changes introduced by the merge, preserving the history for other developers. ... This creates a new commit that reverses the merge without rewriting history.
๐ŸŒ
Reddit
reddit.com โ€บ r/github โ€บ i had a branch merge that was reverted as a side-effect of a bigger reversion. what's the best way to get that one branch commit back in?
r/github on Reddit: I had a branch merge that was reverted as a side-effect of a bigger reversion. What's the best way to get that one branch commit back in?
March 2, 2023 -

Branches are named after an organizational ticket. So lets say we have branches (from oldest to newest) First, Second, OG, Fourth, Fifth

These were all branched from, and then merged back into the Working branch.

At some point recently, the range from newest to oldest of the above commits was targeted for git revert.

In doing so, my merge (OG) was also reverted.

How do I put that one commit back while leaving the others out?

๐ŸŒ
Joohyun Ha
mangchhe.github.io โ€บ git โ€บ 2024 โ€บ 01 โ€บ 25 โ€บ merge-but-no-m-option-was-given
Error: commit {hash} is a merge but no -m option was given. | MyLifeForCoding
January 25, 2024 - -m ์˜ต์…˜์„ ํ†ตํ•ด mainline์„ ์ง€์ •ํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค. ๋กœ๊ทธ๋ฅผ ๊ทธ๋ž˜ํ”„๋กœ ํ™•์ธํ•˜๋ฉด ํ˜„์žฌ 44a074a ์ปค๋ฐ‹์˜ ๋ถ€๋ชจ๋Š” ์ˆœ์„œ๋Œ€๋กœ 975dc09(1), 7d4be38(2)์ด๋‹ค.
๐ŸŒ
Graphite
graphite.com โ€บ guides โ€บ git-error-is-a-merge-but-no-m-option-was-given
"is a merge but no -m option was given" - Graphite
When trying to commit a merge manually without specifying the parent. The error appears because Git is expecting more information to execute a merge commit.
๐ŸŒ
Reddit
reddit.com โ€บ r/git โ€บ remove all changes merged from a specific branch
r/git on Reddit: Remove all changes merged from a specific branch
July 18, 2024 -

Hi,

So Ive been working with git (on azure, dont judge). I have a "release candidate" branch. I also have branches for each additional feature that I am adding.

So the process I currently do is to do whatever changes etc to the feature branch, check it builds then make a pull request to the RC branch, which is then merged in. If there happens to be something missing or broken then great, more changes to feature branch, then PR into RC branch, same process.

HOWEVER!

How do I handle it if at some point we decide that ok, we need to release the RC, but $feature is not ready yet - lets remove/revert all of the Pull request merges that came from that branch? (and I will then refactor and put them into the next release's RC branch)

So please let me know:

  1. am I doing something incredibly stupid.... :D

  2. what is the "sane" way to handle this?

(please be nice if Ive understood something incorrectly)