[Solved-5 Solutions] How to resolve “Error: bad index Fatal: index file corrupt” when using Git
Error Description :
- After
git init,
if we add and commit a few files, make some changes, add and committed. Set up the git daemon (running under Cygwin on WinXP) and clone the repository once, We get this error with the cloned repository:
$ git status
error: bad index file sha1 signature
fatal: index file corrupt
click below button to copy the code. By Git tutorial team
- Is there any way to fix this, other than getting a new copy of the repository?
Solution 1:
- If the problem is with the index as the staging area for commits (i.e.
.git/index
), we can simply remove the index (make a backup copy if we want), and then restore index to version in the last commit: - On OSX/Linux:
rm -f .git/index
git reset
click below button to copy the code. By Git tutorial team
- On Windows:
del .git\index
git reset
click below button to copy the code. By Git tutorial team
- (The
reset
command above is the same asgit reset --mixed HEAD
) - We can alternatively use lower level plumbing
git read-tree
instead ofgit reset.
- If the problem is with index for packfile you can recover it using
git index-pack
.
Solution 2:
- We could try the following to get (possibly?) more information:
git fsck --full
click below button to copy the code. By Git tutorial team
Solution 3:
- This issue can occur when there is a
.git
directory underneath one of the subdirectories. To fix it, check if there are other .git directories there, and remove them and try again.
Solution 4:
- Clone a new copy of the repo elsewhere
- Copy the fresh .git directory into the (broken) repo that contained the changes I wanted to commit
Solution 5:
- This might solve our problem.
rm .git/index
git reset