[Git] Error: fatal: cannot do a partial commit during a merge — Finish resolving conflicts before committing — How to Fix It

Summary

fatal: cannot do a partial commit during a merge appears when you try to commit only certain files while a merge is still in progress. Git blocks partial commits during merges because it requires all conflicts to be resolved in a single, consistent snapshot before completing the operation.

Context

When a merge results in conflicts, Git pauses the process and marks conflicted files as unmerged. You must resolve every conflict before committing. Trying to commit only some files (e.g., with git commit file.txt) leads to this error — Git refuses partial commits in merge mode.

Probable Cause

  • Attempting to commit specific files while a merge is incomplete.
  • Leaving unresolved files in conflict state and using git commit <file>.
  • Merge process interrupted mid-way (IDE, GUI, or manual interruption).
  • Existing merge metadata (.git/MERGE_HEAD) still active from a previous failed merge.

Quick Fix

  1. Check which files are in conflict:
    git status

    Look for Unmerged paths.

  2. Resolve each conflict manually:

    Open the files and remove markers:

    <<<<<<< HEAD
    Your local version
    =======
    Incoming version
    >>>>>>> branch-name
  3. Mark resolved files as staged:
    git add <file>
  4. Complete the merge with a single commit:
    git commit
  5. If you want to abort the merge:
    git merge --abort
  6. Verify the merge result:
    git log --oneline -n 3

Example

# Error
$ git commit file.txt
fatal: cannot do a partial commit during a merge

# Fix
$ git status
Unmerged paths:
  both modified: src/app.js

$ nano src/app.js
# (resolve conflicts)

$ git add src/app.js
$ git commit
Merge made by the 'ort' strategy.

Alternate Scenarios

  • Using VS Code or GUI tools: Partial commits are often blocked until all conflicts are staged.
  • In a rebase: Similar behavior — you must finish all conflict resolutions before continuing.
  • After crash or interruption: Stale merge data in .git/MERGE_HEAD may trigger the error. Use git merge --abort to clean up.

Pitfalls & Debug

  • Symptom → Git refuses commit during merge. Fix → Stage all resolved files, then commit without specifying filenames.
  • Symptom → Merge aborted accidentally. Fix → Re-run the merge and resolve again.
  • Symptom → Unmerged files remain after commit. Fix → Use git diff --check to ensure all markers are removed.

Verification & Next Steps

# Confirm no unmerged paths remain
git status

# Check for leftover conflict markers
git diff --check

# Ensure merge commit exists
git log --oneline -n 3

Best Practices

  • Always resolve all conflicts before committing a merge.
  • Use git add -u to stage all resolved files efficiently.
  • Never use git commit <file> during a merge — it triggers this error.
  • If stuck, git merge --abort is the cleanest way to reset.

Sources

Git Documentation — git merge

Stack Overflow — partial commit during merge

Labels

Tool/Git, OS/Cross-platform, Topic/Merge Conflict Resolution