How to fix error: commit abc1234 is a merge but no -m option was given in Git

GitINTERMEDIATELOWUpdated Dec 6, 2025ยท 241 views

This error occurs when you try to revert a merge commit without specifying which parent to use. Git requires the -m option to determine which branch's changes to undo.

Quick fix

Fixes error: commit abc1234 is a merge but no -m option was given

git log --oneline <commit-hash> -1
  1. Identify the merge commit
  2. Understand parent numbering
  3. Revert the merge commit with -m 1
  4. Handle the revert commit message
git โ€” error
git log --oneline <commit-hash> -1
error: commit abc1234 is a merge but no -m option was given

What this error means

When you attempt to revert a merge commit using `git revert <commit>`, Git refuses because merge commits have two parent commits, not one. A regular commit has a single parent, so Git knows exactly what changes to undo. But a merge commit represents the joining of two branches, each with their own history. Git needs you to tell it which parent to treat as the "mainline" - the branch you want to keep as-is. The other parent's changes will be reverted. This is what the `-m` (or `--mainline`) option does: it specifies the parent number (1 or 2) that represents the original branch you merged into. For example, if you merged a feature branch into main, parent 1 is typically the main branch (the branch you were on when you ran `git merge`), and parent 2 is the feature branch. Using `git revert -m 1 <merge-commit>` keeps main's history and reverts the feature branch's changes.

Typical symptoms

  • Running git revert on a merge commit fails immediately with 'no -m option was given'
  • The error message shows 'commit <hash> is a merge but no -m option was given'
  • git log shows the commit has a 'Merge:' line with two parent hashes
  • Attempting to undo a merged feature branch without specifying parent fails
  • CI/CD automation scripts that revert commits fail on merge commits

Common causes

  1. Attempting to revert a merge commit without the required -m flag (most common)
  2. Not understanding that merge commits have two parents requiring explicit parent selection
  3. Automated scripts or aliases that work for regular commits but fail on merges
  4. Confusion about which parent number (1 or 2) to use for the revert
  5. Trying to use git revert the same way for all commit types
  6. GUI tools that don't expose the -m option or handle it poorly

How to fix "error: commit abc1234 is a merge but no -m option was given"

1Identify the merge commit

First, confirm the commit you want to revert is actually a merge commit:

bash
git log --oneline <commit-hash> -1

If it's a merge, you'll see something like:

bash
abc1234 Merge branch 'feature-x' into main

To see the parent commits:

bash
git cat-file -p <commit-hash>

This shows both parents. The first listed is parent 1, the second is parent 2.

2Understand parent numbering

The parent number determines which branch's state Git reverts to:

- Parent 1 (-m 1): The branch you were on when you ran git merge. Usually main/master.
- Parent 2 (-m 2): The branch that was merged in. Usually your feature branch.

You can visualize this with:

bash
git log --graph --oneline <commit-hash>^1 <commit-hash>^2 -5

Or check the merge commit message which typically says "Merge branch 'X' into Y" - Y is parent 1, X is parent 2.

3Revert the merge commit with -m 1

In most cases, you want to undo the feature branch changes while keeping main's history. Use:

bash
git revert -m 1 <merge-commit-hash>

This creates a new commit that undoes all changes brought in by the merged branch.

Example:

bash
git revert -m 1 abc1234

Git will open your editor for the commit message. The default message explains what was reverted.

4Handle the revert commit message

Git generates a default commit message like:

bash
Revert "Merge branch 'feature-x' into main"

This reverts commit abc1234, reversing
changes made to 8989ee0.

You can:
- Accept the default message by saving and closing the editor
- Customize it to explain why you're reverting
- Use --no-edit to skip the editor: git revert -m 1 --no-edit <hash>

5Verify the revert worked correctly

After the revert, confirm the changes were undone:

bash
# See what changed
git diff HEAD~1

# Check the log
git log --oneline -3

# Verify specific files are restored
git show HEAD --stat

The reverted files should now match their state before the merge.

6Push the revert commit

Once you've verified the revert is correct, push it:

bash
git push origin <branch-name>

Important: Unlike git reset, this creates a new commit rather than rewriting history, so it's safe to push to shared branches.

7Know how to re-merge if needed later

Critical caveat: After reverting a merge, you cannot simply re-merge the same branch later. Git sees those commits as already merged.

To re-merge the feature branch later, you must first revert the revert:

bash
# Find the revert commit
git log --oneline | grep "Revert"

# Revert the revert
git revert <revert-commit-hash>

# Now you can merge again (or the original changes are back)
git merge feature-branch  # if there are new commits
8Alternative: Use git reset for unpushed merges

If you haven't pushed the merge yet, git reset is simpler:

bash
# Undo the merge entirely (moves HEAD back)
git reset --hard HEAD^

# Or keep changes in working directory
git reset --soft HEAD^

Warning: Only use git reset on commits you haven't shared with others. It rewrites history.

Advanced notes

### Choosing Between -m 1 and -m 2

The choice of parent affects what the repository looks like after the revert:

- -m 1: Keeps the state of the target branch (where you merged into), undoes the source branch changes
- -m 2: Keeps the source branch changes, undoes the target branch's changes since the merge base

Almost always, you want -m 1 because you're undoing a feature that was merged in, not undoing your main branch.

### The "Revert of Revert" Problem

When you revert a merge, Git records that those commits were "merged and then undone." If you later try to merge the same branch again, Git won't bring in the old commits because it thinks they're already incorporated.

Solutions:
1. Revert the revert before re-merging (creates clean history)
2. Cherry-pick the specific commits you need instead of merging
3. Rebase the feature branch to create new commit hashes (more complex)

### Reverting Multiple Merge Commits

If you need to revert multiple merge commits, revert them in reverse chronological order:

bash
git revert -m 1 <newest-merge>
git revert -m 1 <older-merge>
git revert -m 1 <oldest-merge>

### Merge Commits in Git Bisect

When bisecting and you hit a merge commit, you may need to specify which parent to follow. Use:

bash
git bisect good <merge-commit>^1
# or
git bisect bad <merge-commit>^2

### GUI Tools

Some GUI tools hide the complexity:
- GitKraken: Right-click merge commit > Revert (handles -m automatically)
- SourceTree: May require manual intervention for merge reverts
- VS Code GitLens: Shows both parents, lets you choose

Frequently asked questions

What does "error: commit abc1234 is a merge but no -m option was given" mean?
When you attempt to revert a merge commit using git revert <commit>, Git refuses because merge commits have two parent commits, not one. A regular commit has a single parent, so Git knows exactly what changes to undo. But a merge commit represents the joining of two branches, each with their own history.
How do I fix "error: commit abc1234 is a merge but no -m option was given"?
This error occurs when you try to revert a merge commit without specifying which parent to use. Git requires the -m option to determine which branch's changes to undo.
What causes "error: commit abc1234 is a merge but no -m option was given"?
Attempting to revert a merge commit without the required -m flag (most common) Not understanding that merge commits have two parents requiring explicit parent selection Automated scripts or aliases that work for regular commits but fail on merges
Is the "error: commit abc1234 is a merge but no -m option was given" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading