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:
Delete the index
$ rm .git/index
Add all
$ git add -A
Commit
$ git commit -a
Original answer (late 2014)
The usual workaround is to:
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.
rm .git/index
git reset
after deleting index you need to recreate it by git reset
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 .
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With