This could happen when some files in the
.git folder, specifically the
index is damaged.
to fix it try (in linux):
rm -f .git/index
git reset --keep
To reproduce the error:
arie@dev:/var/www/repo$ ls -lha .git/ # Ver los archivos de .git/
[... otros archivos ...]
-rw-r--r-- 1 arie arie 175K mar 2 13:18 index # Fichero correcto
arie@dev:/var/www/repo$ git add . # Este funciona!
arie@dev:/var/www/repo$ truncate -s 1000 .git/index # Echamos a perder :(
arie@dev:/var/www/repo$ git add . # Error!
error: bad index file sha1 signature
fatal: index file corrupt
The Index file
The staging area is a file, usually contained in your Git directory, that stores information about what will go into your next commit. It's sometimes referred to as the "index", but it's also common to refer to it as the staging area. The Three States - Git Basics
The "index", "stagging area" or "preparation area" is a file that contains the capture of the current working tree that will be included in the next "commit".
The git reset [< mode >] [< commit >]
This form resets the current branch head to < commit > and possibly updates the index (resetting it to the tree of < commit >) and the working tree depending on < mode & gt ;. Git reset - git documentation
Git reset relocates the "head" pointer to the selected commit between
< > , along with this updates the "index" file. If paramatro
<commit> is not provided, by default it is
HEAD . For
option - keep
Resets index entries and updates files in the working tree that are different between < commit > and HEAD. If a file that is different between < commit > and HEAD has local changes, reset is aborted. Option --keep - Git Documentation
You can read this article on the git-scm blog (in English) to have much more information.