Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a fatal error in git for multiple stage entries

Tags:

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.


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

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.


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

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

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