Getting a fatal error in git for multiple stage entries

Using Git version 2.2.0 with unity game engine on OS X, and wanted to commit my code. I added everything and did not get an error message. then commit -m , and got this error message:

fatal: multiple stage entries for merged file 'Assets/Prefabs/Resources'

Not noticing it I pushed, that didn't give an error message, in fact said Everything up-to-date So I checked bitbucket (where the repo is held) and it didn't show my commit. so I checked my local log and that also does not show my commit.

I've looked into google for an answer... and nothing. what is this error? and how can I fix it?


The first workaround, which seems to work with recent versions of Git (2.3+, Q2+ 2015) is mentioned in grant's more up-to-date answer:

  1. Delete the index

    $ rm .git/index
    
  2. Add all

    $ git add -A
    
  3. Commit

    $ git commit -a
    

Original answer (late 2014)
The usual workaround is to:

  • clone again the remote repo into a new local repo
  • add the changes from the first repo to the second one:

    $ cd /patH/to/second/cloned/repo
    $ git --work-tree=/path/to/first/repo add .
    

You can see this error message in read-cache.c, discussed in this patch ("read-cache.c: Ensure unmerged entries are removed "), and introduced in the Git 2.2 commit.
Since this is so recent, it is possible that downgrading Git to 2.1 would be enough to not be affected by that patch.

The OP Daniel Toebe adds in the comments:

The issue happened on my macbook, which decided to fail on me, and another computer mishap put me way behind on my projects.


I believe I encountered this issue because I added and committed changes and then deleted a file that I had just committed. If this sounds similar to your case, I recommend following the below to save re-cloning and manually adding in your changes.

I was able to fix this issue by deleting the .git/index file in my repository, similar to what @slider suggested (I believe he mistyped the path).

rm .git/index

Then I had to add and commit my local changes again

git add -A
git commit -m "..."

I was then able to push remotely.

What is the git index and how is it relevant?

What’s The Deal With The Git Index?

The git “index” is where you place files you want committed to the git repository.

Before you “commit” (checkin) files to the git repository, you need to first place the files in the git “index”.

I believe that by deleting this file, git will re-index the repo, create a new one and you're good to go. It solves this problem because the local repository is re-indexed without the file I deleted that caused all the fuss.

Edit: It seems like this is Mac related (based on comments) so if it helps I'm on OSX 10.10 and git version 2.3.4 installed through brew.


For project

rm .git/index
git reset

after deleting index you need to recreate it by git reset

For submodule:

Go to main project folder

rm .git/modules/your_project_structure/index
git reset --hard HEAD