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

GitGit Merge

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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.

Solution 3 - Git

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.

Solution 4 - Git

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.

Solution 5 - Git

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

Solution 6 - Git

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

Those files had to be removed using git rm

Solution 7 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKiarashView Question on Stackoverflow
Solution 1 - GitjonnystotenView Answer on Stackoverflow
Solution 2 - GitPrabhakar UndurthiView Answer on Stackoverflow
Solution 3 - GitmumanView Answer on Stackoverflow
Solution 4 - GitPriyanka AroraView Answer on Stackoverflow
Solution 5 - GitmacabeusView Answer on Stackoverflow
Solution 6 - GitYann VRView Answer on Stackoverflow
Solution 7 - GitappdesignsView Answer on Stackoverflow