Git merge error "commit is not possible because you have unmerged files"
Solution 1
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
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
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
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
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
Related videos on Youtube
Kiarash
Updated on July 08, 2022Comments
-
Kiarash almost 2 years
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.
-
Henke over 3 yearsYou 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.
-
-
R11G almost 11 yearsWhat 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?
-
Brendon Muir over 7 yearsI 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. -
polina-c over 5 yearshow to find list of conflicts?
-
jonnystoten over 5 years
git status
will show you the files that have conflicts -
Rais Iqbal over 5 yearsIt is not required only git add . would suffice
-
courtsimas over 5 yearsAlso this is a heavy hitter if you're not wanting to
git add
all your working files -
Yuri Predborski about 5 years@jonnystoten thanks for your comment! I used
git status
and found a file that saidboth deleted
. WebStorm UI didn't show the problem, just said it couldn't commit a merge. Resolved! -
Alexander Samoylov almost 5 yearsI 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".
-
Josh Bone about 3 yearsDo not run "git add ." unless you are ready to add all local files to your GitHub repo.
-
shubham rajput almost 3 yearsIf you do not want to add that file in your commit and you are getting the error even after resolving the commit, simply stage and un-stage that file fixed the error for me.
-
ElsayedDev almost 3 yearsplease don't use stash .. it we remove all u changed
-
Zon over 2 yearsThis 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 pastesrc
back.