Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Git merge error "commit is not possible because you have unmerged files"

Writer Andrew Henderson

I forgot to git pull my code before editing it; when I committed the new code and tried to push, I got the error "push is not possible".

At that point I did a git pull which made some files with conflict highlighted. I removed the conflicts but I don't know what to do from here.

I tried to git commit again but it says the "commit is not possible because you have unmerged files":

error: Committing is not possible because you have unmerged files.
1

7 Answers

If you have fixed the conflicts you need to add the files to the stage with git add [filename], then commit as normal.

7

You need to do two things. First add the changes with

git add .
git stash
git checkout <some branch>

It should solve your issue as it solved to me.

5

You can use git stash to save the current repository before doing the commit you want to make (after merging the changes from the upstream repo with git stash pop). I had to do this yesterday when I had the same problem.

This error occurs when you resolve the conflicts but the file still needs to be added in the stage area. git add . would solve it. Then, try to commit and merge.

Since git 2.23 (August 2019) you now have a shortcut to do that: git restore --staged [filepath]. With this command, you could ignore a conflicted file without needing to add and remove that.

Example:

> git status ... Unmerged paths: (use "git add <file>..." to mark resolution) both modified: file.ex
> git restore --staged file.ex
> git status ... Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: file.ex

I've had a similar issue which boiled down to removing files under "unmerged paths"

Those files had to be removed using git rm

So from the error above. All you have to do to fix this issue is to revert your code. (git revert HEAD) then git pull and then redo your changes, then git pull again and was able to commit or merge with no errors.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy