255

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
  • 1
    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 or git pull -X theirs. - Probably not both, but I am not sure. Commented Dec 17, 2020 at 8:13

8 Answers 8

352

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

Sign up to request clarification or add additional context in comments.

7 Comments

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?
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.
how to find list of conflicts?
git status will show you the files that have conflicts
@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!
|
72

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 Comments

It is not required only git add . would suffice
Also this is a heavy hitter if you're not wanting to git add all your working files
Do not run "git add ." unless you are ready to add all local files to your GitHub repo.
please don't use stash .. it we remove all u changed
This way you will get rid of the blocking message, but resolved conflict changes will also be rolled back. If you want to keep them - copy src folder, do what's in this answer, and paste src back.
13

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.

Comments

13

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.

Comments

7

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 

2 Comments

is there anyway to apply this command to all files, since I've quite a lot of files needing merge, and applying this command to each file by name will be quite hectic task
@Lint You can apply for all files within a path. For example: git restore --staged . or git restore --staged folder/
2

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

Those files had to be removed using git rm

Comments

1

I just used the option "reset HEAD" under Git in Android Studio.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.