Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve "Error: bad index – Fatal: index file corrupt" when using Git

Tags:

git

corruption

After git init, I added and committed a few files, made some changes, added and committed. Set up the git daemon (running under Cygwin on WinXP) and cloned the repository once. Now, I get this error with the cloned repository:

$ git status error: bad index file sha1 signature fatal: index file corrupt 

Is there any way to fix this, other than getting a new copy of the repository?

like image 230
Number8 Avatar asked Jul 12 '09 11:07

Number8


People also ask

How do I fix a corrupted index in git?

To rebuild the index, you can simply do git reset --mixed . This makes the index look like the last commit while leaving the worktree alone. If you had any local changes you git add ed but did not commit yet, you will need to re-add those.

How do I fix a corrupted index file?

To rebuild the index of a corrupt indexed file, make sure that the corrupt indexed file is not still open in the Data File Editor. Then, click Data Tools>Fix File Index on the Tools menu.

What is a git index file?

The Git index is a critical data structure in Git. It serves as the “staging area” between the files you have on your filesystem and your commit history. When you run git add , the files from your working directory are hashed and stored as objects in the index, leading them to be “staged changes”.


1 Answers

If the problem is with the index as the staging area for commits (i.e. .git/index), you can simply remove the index (make a backup copy if you want), and then restore index to version in the last commit:

On OSX/Linux/Windows(With Git bash):

rm -f .git/index git reset 

On Windows (with CMD and not git bash):

del .git\index git reset 

(The reset command above is the same as git reset --mixed HEAD)

You can alternatively use lower level plumbing git read-tree instead of git reset.


If the problem is with index for packfile, you can recover it using git index-pack.

like image 180
Jakub Narębski Avatar answered Sep 20 '22 14:09

Jakub Narębski