How to Fix Git Index File to Recover from the Error "index file corrupt" or ".git/index.lock: File exists."

Error from Broken Git Index File

If you see an error report dialog that includes a message like the following, the Git index file for the project is broken.

fatal: index file corrupt

It is possible that rebuilding the Git index file brings the project back to its normal status. This Note explains how to do it.

Error from Locked Git Index File

Also, if you see an error message like the following instead, it means the Git index file is locked.

fatal: Unable to create '.../.git/index.lock': File exists.

It is possible that unlocking it might bring the project back to its normal status. This Note explains how to do it as well.

Obtain the ID of the Project

For both types of errors, the first step is to obtain the project ID so that we know for which project we should unlock or rebuild the Git index file.

Open the System Configuration Dialog, and select "User Preferences" tab.

Select Yes for "Show Metadata ID on Name / Comment Dialog.". Click the OK button.

Then, if you open the Update Project Dialog from the Rename menu, you can see the project's ID.

In this example, ID is IDG9GQF2.

Move to the Project Directory

With the project ID, now we know which directory the project is kept in.

With a Command Prompt or Terminal, move to the directory of the project in question. In this example, it would be the directory in the following command. (The following command assumes that your repository is in .exploratory directory directly under your home directory. If your repository is at a custom location, please adjust the command.)

cd
cd .exploratory/projects/IDG9GQF2

Unlock the Git Index File

After moving to the project directory, if the Git index file of your project is locked, try unlocking it with the following command on the Command Prompt or Terminal.

Windows:

del .git\index.lock

Mac:

rm .git/index.lock

After that, try reopening the project and see if you can make changes without the error report dialog popping up.

If the error fatal: index file corrupt happens, rebuild the Git index file following the instruction below.

Rebuild the Git Index File

After moving to the project directory, try the following commands to remove the Git index file and rebuild it.

Windows:

del .git\index
git reset

Mac:

rm .git/index
git reset

After that, try reopening the project and see if you can make changes without the error report dialog popping up.