问题
No git's command is working anymore created a branch, made some commits. Then I made a recursive find and replace as so :
LANG=C find . -type f -name '*.*' -exec sed -i '' s/My\ sentence/My\ sentencevotre/ {} +
which worked properly, but now I can't commit, I can't reset hard, I have a serie of messages when reseting : error: packfile .git/objects/pack/pack-$SHA.pack does not match index ...
and when commiting :
warning: packfile .git/objects/pack/pack-$SHA.pack cannot be accessed .... error: invalid object 100644 $SHA for 'Doxyfile' error: Error building trees
How can I manage this ?
回答1:
Undo your find and replace and try again. Maybe you are lucky enough ... otherwise use your backup.
Be more careful with your .git directory next time.
回答2:
It seems that you changes files inside you .git folder, which defines the repository. I don't know any other solution for that than deleting .git folder and recreating a new git repository inside the folder. This shouldn't be a big problem if you have a remote repository like GitHub.
来源:https://stackoverflow.com/questions/14564936/git-reset-failing-after-find-and-replace