Git merge is not possible because I have unmerged files

Viewed 265564

git continues to confuse me with its unhelpful error warnings This one really deserves a prize:

git merge is not possible because you have unmerged files

My situation: My master branch on github was edited (directly in the browser) while my local master branch was also edited.

I wrongly suppose you could simply merge the two versions and be done with it, but also, I cannot merge - because my files are unmerged.

git merge remote/master

results in

error: merge is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

So, after adding and committing the local change and then trying to merge again, I get:

merge: remote/master - not something we can merge

Clearly I am missing something essential here... Do I have the wrong idea about what merging means? How do I fix this issue of having a different remote master / local master branch?

9 Answers

It might be the Unmerged paths that cause

error: Merging is not possible because you have unmerged files.

If so, try:

git status

if it says

You have unmerged paths.

do as suggested: either resolve conflicts and then commit or abort the merge entirely with

git merge --abort

You might also see files listed under Unmerged paths, which you can resolve by doing

git rm <file>

I also had similar problems.

My probblem: when I merge branch, and resolve conflicts with IDE, the IDE will show commit panel board normally, but it does not.

I think I have merged successfully, but when I push or pull,git remind me " commit your changes before merging" or "Updates were rejected because the tip of your current branch is behind".

My solution: git merge --continue

if you want to abort this merge ,you can also run git merge --abort

The simple way is type git status into your terminal window/cmd. This should show you the files that either need to be added or removed enter image description here

and then you can either do git add followed by the file path or remove them with git rm also followed by the file path.

Another potential cause for this (Intellij was involved in my case, not sure that mattered though): trying to merge in changes from a main branch into a branch off of a feature branch.

In other words, merging "main" into "current" in the following arrangement:

main
  |
  --feature
      |
      --current

I resolved all conflicts and GiT reported unmerged files and I was stuck until I merged from main into feature, then feature into current.

Something that happened to me, if you tried to do merge before and resolved some conflicts on the incoming branch, git can do some changes on its own on your current branch, so try git status even if you are sure that no modifications have been made by yourself, then something like this might appear: They did it!

then simply do git add . git commit -m "message" and try to do the merge again

try

git add *
git commit -comment
git pull

Explanation git add * : Means you are adding all files that are not added' git commit -comment : You are committing file you have just added git pull : You are now getting changes from online version

Related