Getting a fatal error in git for multiple stage entries

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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

Solution 4 - Git

You can remove Git index file from your project. In the root of your project, run the following command:

rm .git/index

After that git it work.

Solution 5 - Git

I try a different solution and it works for me. Below are my options

#cd .git
#rm index
#cd ..
#git add .

Solution 6 - Git

If this happens in a submodule

The index file is located inside the parent .git directory:

.git/modules/your_project_structure/index

In a submodule, there are no directories named .git (at least in the project I'm working on), there's only a .git file which tells you (and git) where to look for the git directory of that project.

Git status shows changes that I didn't make

After removing the index files, and doing a git reset, I found myself facing lots of inexplicable changes and a hard reset wasn't helping.

Warning you'll lose all your changes, so commit them and push before continuing.

The index seemed corrupted, so I removed it with the following commands.

git rm -rf --cached .
git reset --hard HEAD

Solution 7 - Git

I just got this error with the Github Desktop Client (OSX). All I did was quit the app and reopened and then it started working.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniel ToebeView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitgrantView Answer on Stackoverflow
Solution 3 - GitfarinczView Answer on Stackoverflow
Solution 4 - GitsliderView Answer on Stackoverflow
Solution 5 - GitwqycsuView Answer on Stackoverflow
Solution 6 - GitEmile BergeronView Answer on Stackoverflow
Solution 7 - GitOrenView Answer on Stackoverflow