I did a commit with a lot of work and accidentally a folder of images which was huge. I then did a git reset --hard HEAD^ and thought it would just remove the commit. But it turned out it also removed all the work I had done ... huge bummer.
Now, I've read hundreds of posts about recovering from that exact accident. But no matter what I try, I simply cannot recover all the edited files and folders I've created during the last days.
HOW, can I make git give me back the lost files?
OK. Obviously clearly overworked here ... what I did was:
git add .
And then after seeing my mistake I did a:
git reset --hard HEAD^
Yes, totally screwing around here.
How do I recover from this situation?
After git fsck --lost-found
tells you about all the "dangling blob"s it saved, look in .git/fsck/lost-found/other
. There are many files in here, with completely useless names (actually just hash IDs), but with the contents of the files that you had git add
-ed that were not already in your repository.
You can either go through the files as they are here, or copy or move them out to a temporary area elsewhere. You must look at each file, figure out what name it should have or whether you want to keep it at all, and if so, give it a better name.
The original file names are not saved anywhere in Git (they were in your index, but git reset --hard
overwrote that index with the current index). (They would have been saved beneath a commit, had you made a commit.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.