197

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.
pkamb
  • 26,648
  • 20
  • 124
  • 157
Kiarash
  • 5,626
  • 7
  • 38
  • 67
  • You might want to change your git workflow so that you never arrive in this situation in the first place. I don't have time to elaborate on it right now, but what I have in mind includes either [git merge -X theirs](https://stackoverflow.com/a/3364506) or [git pull -X theirs](https://stackoverflow.com/a/21777677). - Probably not both, but I am not sure. – Henke Dec 17 '20 at 08:13

7 Answers7

291

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

jonnystoten
  • 6,285
  • 2
  • 28
  • 36
  • 3
    What if those are the files I have not been working on? Should I then still add them? What is the best way to deal with it? – R11G Jun 19 '13 at 12:50
  • 1
    I had to do this for a file that was deleted in a branch that I was merging into the current branch. Git flagged it as a conflict, so I had to delete the file locally then `git add the_file` in order to commit the merge. – Brendon Muir Sep 15 '16 at 23:14
  • how to find list of conflicts? – polina-c Aug 08 '18 at 17:32
  • 15
    `git status` will show you the files that have conflicts – jonnystoten Aug 08 '18 at 18:03
  • @jonnystoten thanks for your comment! I used `git status` and found a file that said `both deleted`. WebStorm UI didn't show the problem, just said it couldn't commit a merge. Resolved! – Yuri Predborski Mar 28 '19 at 08:45
  • I think the answer "git add" is correct, but not complete. If I have a merge conflicts during cherry-pick and do "git add" + "git commit" as suggested I get the error: "fatal: cannot do a partial commit during a cherry-pick.". In this case I have to do this: "git add" + "git cherry-pick --continue" + "git push". – Alexander Samoylov May 09 '19 at 14:23
60

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.

Prabhakar Undurthi
  • 5,818
  • 2
  • 36
  • 46
11

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.

muman
  • 124
  • 6
4

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.

greg-449
  • 102,836
  • 220
  • 90
  • 127
Priyanka Arora
  • 229
  • 1
  • 9
4

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

macabeus
  • 3,268
  • 2
  • 28
  • 49
1

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

Those files had to be removed using git rm

Yann VR
  • 456
  • 5
  • 8
0

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.

Brydenr
  • 791
  • 1
  • 18
  • 27
appdesigns
  • 72
  • 10