47

I had about 12 file conflicts when I merged branches. I manually fixed all the conflicts and staged the files. But now when I try to commit, it says one of the files is unmerged.

U      app/models/disclosure_event.rb
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

When I type git status, it shows all the changed files, including "disclosure_event.rb", under Changes to be committed. It shows no files as unstaged. I've repeatedly tried to add the file, but it seems to do nothing. If I open the file, everything looks great.

Any ideas? I'm completely stuck.

Adam Albrecht
  • 6,680
  • 4
  • 31
  • 35
  • 1
    Sounds like yet another Git bug..... – Pacerier Oct 20 '15 at 11:05
  • Possible duplicate of [Git: can't undo local changes (error: path ... is unmerged)](http://stackoverflow.com/questions/3021161/git-cant-undo-local-changes-error-path-is-unmerged) – Stewart Apr 04 '17 at 10:10

5 Answers5

71

I can't tell you what's wrong, but you might try

git reset app/models/disclosure_even.rb
git add app/models/disclosure_even.rb

and then commit.

Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • 1
    I had to use "git reset -- lib/OaisAip.php", but that got me going! – Mark Leighton Fisher Dec 20 '13 at 15:05
  • 2
    I had to specify `git reset HEAD app/models/disclosure_even.rb`. Otherwise, I'd get `git reset app/models/disclosure_even.rb => fatal: ambiguous argument 'app/models/disclosure_even.rb': unknown revision or path not in the working tree. Use '--' to separate paths from revisions` – Dan Dascalescu Apr 14 '14 at 22:21
14

I had exactly the same situation today on branches merging (not rebasing).

I spot, that file it errors on, in your case:

U      app/models/disclosure_event.rb

was absent in git status. But is could be seen as unmerged in gitk GUI. It also was absent in working copy (moved to another place in my case).

I tried git rm, and it solved the problem:

git rm app/models/disclosure_event.rb
alexkasko
  • 4,855
  • 1
  • 26
  • 31
8

Set the remote is origin and the branch is master, and say you already have master checked out, might try the following:

git fetch origin
git reset --hard origin/master

It will set the current branch and points it to the HEAD of the remote branch.

Md. Ranju Mia
  • 164
  • 2
  • 6
3

I encountered such situation before with rebase. Git determines that you leave some files as they were before merge and thinks you still didn't merge them. That time I googled and find out many suggestions to do just git rebase --skip. It worked for me.

More detailed description of such case: http://git.661346.n2.nabble.com/BUG-git-rebase-is-confuse-if-conflict-resolution-doesn-t-produce-diff-td726597.html

Similar problem: Git rebase: conflicts keep blocking progress

I'm not sure it is your case if you have merge, though.

Community
  • 1
  • 1
Ivan Danilov
  • 14,287
  • 6
  • 48
  • 66
3

I tried the 2 suggestions without any luck. And I couldn't get it to reset back to HEAD, so I just re-cloned the repository and did the entire merge over and didn't have any issues. For what it's worth, I now highly recommend p4merge over vimdiff...

Adam Albrecht
  • 6,680
  • 4
  • 31
  • 35