When submitting the file to the warehouse, the following error is thrown:
Report an error
Roc@DESKTOP-AF552U2 MINGW64 /e/note/Git (master)
$ git add git_GitHub.md
error: bad signature
fatal: index file corrupt
Cause Analysis
Because index file generally refers to the file .git/index in git. This file saves the information in the temporary storage area (index information). You can use git ls-files –stage to view the contents of the staging area. This file is very important! But now it reports index file corrupt, indicating that this file has been damaged. Fortunately, we have a way to regenerate this file: git read-tree or directly git reset.
Solution
- Enter the project directory: cd /path/to/dir
- Delete or rename the .git/index file: rm -f .git/index or mv .git/index{,.bak}
- Rebuild .git/index: git read-tree or directly git reset
Roc@DESKTOP-AF552U2 MINGW64 /e/note (master)
$ mv .git/index .git/index.bak
Roc@DESKTOP-AF552U2 MINGW64 /e/note (master)
$ git reset
Unstaged changes after reset:
M Git/git_use.md
M Git/git_para.md
Roc@DESKTOP-AF552U2 MINGW64 /e/note (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: "Git/git\347\232\204\345\210\235\346\254\241\344\275\277\347\224\250.md"
modified: "Git/git\347\232\204\351\200\211\351\241\271\345\217\202\346\225\260.md"
Untracked files:
(use "git add <file>..." to include in what will be committed)
Git/git failed to push some refs to github.md
"Git/git \346\212\245\351\224\231 index file corrupt.md"
"Git/git\350\277\236\346\216\245GitHub\344\273\245\345\217\212\346\216\250\351\200\201\350\207\263\344\273\223\345\272\223.md"
no changes added to commit (use "git add" and/or "git commit -a")
Roc@DESKTOP-AF552U2 MINGW64 /e/note (master)
Done!