Dan Donaldson
Dan Donaldson

Reputation: 1293

git problem : fatal: Unable to write new index file

I have an existing project that has been managed under git. I recently had to do a ground-up rebuild of the computer (OS X Snow Leopard), and returning to the project, git can track the changes in the project, but I can't save anything to git. I get the error in the title when I try :

Dans-iMac-335:[app-name-obscured] apple$ git add app/models/*
fatal: Unable to write new index file

What's the best way to recover from this situation? There is a heroku repository version of this, but it is very out of sync with this one. presumably I could use a new clone as a basis, and update each file, but that seems over laborious and error prone.

What is git looking for here that it can't find, and is there a change that will restore it?

BTW, file permissions are correct from what I can tell - the files under control and the .git components are both owned by me with rw access...

Upvotes: 33

Views: 44250

Answers (14)

Peter Lund
Peter Lund

Reputation: 1

I had the same problem. "fatal: Unable to write new index file"

I found out that the reason was that my disk was full. I removed something else from it and then my git repo recovered and all worked again.

Upvotes: 0

JonB451
JonB451

Reputation: 80

I had the same error because Google Drive's Backup and Sync client for Windows had not released a lock on two files within this repository. A work around was, after the sync client had finished its work: Process Explorer -> Find -> Find handle or DLL -> Close Handle.

Upvotes: 0

No.8
No.8

Reputation: 1

I had used this problem when using git on visual studio, and my solution was to run visual studio as an administrator

Upvotes: 0

Omegastick
Omegastick

Reputation: 1911

This is old, but the cause for me was Dropbox. My local repository was stored in my Dropbox folder, and I had to pause Dropbox syncing before I could complete the command.

Upvotes: 1

Paulo Borralho Martins
Paulo Borralho Martins

Reputation: 350

I had same problem. I still dunno the cause, but my workaround is delete index.lock sudo rm -f index.lock, and then i gave write permission to index sudo chmod 777 index. After this I am able to stage and commit. The problem is I have to do this almost all the times I have something to stage.

Upvotes: 1

Travis Mathis
Travis Mathis

Reputation: 21

I was able to fix this by going into the .git folder in the git initiated app and deleting the index.lock/index file. I had to reindex the entire app, but it resolved the problem.

Upvotes: 2

kburtsev
kburtsev

Reputation: 1

To add: surprisingly, some git plug-ins blocks index file. My Eclipse Kepler has default plug-in, that occasionally updates some own info from git repo, blocking index file during that operation.

Upvotes: 0

Kanedias
Kanedias

Reputation: 385

I'd like to point out one more cause of this error

If you are cloning a git repository that contains another git repository in it (not submodule), you will get this behaviour.

Hope it'll help somebody.

Upvotes: 1

Valera Dubrava
Valera Dubrava

Reputation: 254

I've had a simular problem with SFTP Network Drive (free). The solution is: fill chekcbox "Delete existing target before moving" found in the Profile Settings of SFTP Network Drive.

Upvotes: 2

Dave Halter
Dave Halter

Reputation: 16335

If you are using sshfs, add the option -o workaround=rename, as described here: http://alan.lamielle.net/2009/07/08/git-over-sshfs

Upvotes: 1

Renklauf
Renklauf

Reputation: 981

I had a similar problem. "git reset --hard" worked for me.

Upvotes: 0

Timmy
Timmy

Reputation: 1493

I just ran into the same situation, it turned out that my filesystem was full.

Upvotes: 64

Scott Silver
Scott Silver

Reputation: 31

I was using Parallels running Ubuntu on my Mac. I could git init, but not git add. I believe the issue is that git add requires an atomic synch to the underlying git database. And since the filesystem I was using was actually on my Mac and Parallels was exporting from my Mac via a network share. I believe this means that git couldn't do what it wanted. Moving the files locally fixed the problem (In my case this was easy since I was using DropBox on my Mac, so I just installed DropBox on my Ubuntu running Parallels)

Upvotes: 3

Rudi
Rudi

Reputation: 19940

Do you have write access to .git (=can you create new files there and edit existing ones)? If not then adjust the file permissions.

If you have write permissions it seems you found a bug. You can try to recover by

  1. create a clone from your current working copy
  2. remove all files from the working copy of the clone
  3. copy all wc files from your current working copy to the clone (and don't copy .git)
  4. try to commit something in the clone.

When the last step works you need setup the remote branches from your current repo to the clone, and then you can use the cloned repo as your new working copy.

Upvotes: 4

Related Questions