/errors/git/cannot-do-a-partial-commit-during-a-merge
git: fatal: cannot do a partial commit during a merge.
- tool
- Git
- exit code
- 128
- versions
- git 2.x
- os
- any
fatal: cannot do a partial commit during a merge. means you ran git commit with file paths while a merge is still open. Git needs a single commit that records the whole merge result. Fix the conflicts, stage the resolved files with git add, then run git commit without paths. To give up, run git merge --abort.
Reproduce it
Two branches change the same line, the merge stops on a conflict, and a commit with a path is attempted:
set -e
git init -q .
git config user.email "dev@example.com"
git config user.name "Dev"
printf 'base\n' > a.txt
git add a.txt
git commit -q -m "base"
git checkout -q -b feature
printf 'feature\n' > a.txt
git commit -q -am "feature change"
git checkout -q -
printf 'main\n' > a.txt
git commit -q -am "main change"
git merge feature || true
git commit -m "resolve" a.txtOutput · exit 128
Auto-merging a.txt CONFLICT (content): Merge conflict in a.txt Automatic merge failed; fix conflicts and then commit the result. fatal: cannot do a partial commit during a merge.
The merge prints CONFLICT (content): Merge conflict in a.txt, which is the normal start of the situation described in automatic merge failed. The last command is the one refused, with exit status 128.
Why Git refuses
During a merge Git keeps a pointer file, .git/MERGE_HEAD, to the commit being merged. The next commit becomes the merge commit and gets two parents. git commit <paths> means "commit only these paths and leave the rest of the index alone", and that cannot produce a merge commit that includes the other branch's changes. Git stops with exit status 128 before it writes anything.
Fix it
- Run
git status. Files under "Unmerged paths" still have conflicts. - Open each conflicted file, remove the
<<<<<<<,=======and>>>>>>>markers and keep the content you want. - Stage each resolved file:
git add a.txt. - Commit without paths:
git commit(Git proposes a merge message) orgit commit -m "Merge feature".
set -e
git init -q .
git config user.email "dev@example.com"
git config user.name "Dev"
printf 'base\n' > a.txt
git add a.txt
git commit -q -m "base"
git checkout -q -b feature
printf 'feature\n' > a.txt
git commit -q -am "feature change"
git checkout -q -
printf 'main\n' > a.txt
git commit -q -am "main change"
git merge feature > /dev/null || true
printf 'resolved\n' > a.txt
git add a.txt
git commit -q -m "Merge feature"
git log --oneline | wc -l
git status --short a.txt | wc -lOutput
4 0
The log now contains four commits, including the merge commit, and a.txt has no pending change. Confirm with git log --graph --oneline.
Abort instead
If the merge was a mistake, git merge --abort restores the state before git merge. It works only while the merge is unfinished. If uncommitted changes existed before the merge, Git tries to restore them but cannot always do it, so commit or stash work before merging.
Prevent it
Start merges from a clean working tree and keep conflict markers out of commits: git diff --check reports leftover markers. Use git commit without paths for every merge, and use git add per file to mark each conflict as resolved. If you prefer a linear history, see merge vs rebase.
FAQ
Why does Git refuse a partial commit during a merge?
A merge commit must record the result of the whole merge and have two parents. Committing only some paths would drop the other side of the merge, so Git requires one commit for the full index.
Can I use git commit -a during a merge?
Yes. git commit -a stages all tracked files and commits them, which is allowed. Only forms that name paths are refused. Make sure no conflict markers remain in the files first.
How do I know a merge is still in progress?
git status prints 'You have unmerged paths' and the file .git/MERGE_HEAD exists. After git merge --abort or the merge commit, both are gone.