I had the same problem (don’t know why).
This fix requires access to an uncorrupted remote copy of the repository, and will keep your locally working copy intact.
But it has some drawbacks:
- You will lose the record of any commits that were not pushed, and will have to recommit them.
- You will lose any stashes.
The fix
Execute these commands from the parent directory above your repo (replace ‘foo’ with the name of your project folder):
- Create a backup of the corrupt directory:
cp -R foo foo-backup - Make a new clone of the remote repository to a new directory:
git clone git@www.mydomain.de:foo foo-newclone - Delete the corrupt .git subdirectory:
rm -rf foo/.git - Move the newly cloned .git subdirectory into foo:
mv foo-newclone/.git foo - Delete the rest of the temporary new clone:
rm -rf foo-newclone
On Windows you will need to use:
copyinstead ofcp -Rrmdir /Sinstead ofrm -rfmoveinstead ofmv
Now foo has its original .git subdirectory back, but all the local changes are still there. git status, commit, pull, push, etc. work again as they should.