How can I recover my commit after I did a git reset
I've been working on a project for months now with regular commits. I use Heroku to store my app. I pushed to Heroku, and then I used the Git GUI to roll back my files to December 7th, and I then force pushed that to Heroku. I was trying to restore a specific folder but did not realize it would restore the whole directory.
I then realized I lost all my commits from December 7th and forward.
I've tried git lost-found and my directory has about 20 heads in the reflog. There is a specific commit I am looking for, I have the hash from Heroku. It is 8d4f84a, but when I do git checkout 8d4f84a it gives me error "Unknown revision or path not found in the working tree."
I did a heroku rollback, and that restored my files on Heroku to the previous push, but I cannot clone those files.
Have I lost all my work up this point?
EDIT: Attached reflog, full of old commits dating to December 7th and back
eb64161 HEAD@{0}: checkout: moving from 4d6a18311433a9bee737eda9bf6114f8bc35fa2c
4d6a183 HEAD@{1}: checkout: moving from master to HEAD@{3}
eb64161 HEAD@{2}: checkout: moving from eb64161f29fff57ab861880c4cd1cdf7641c39bf
eb64161 HEAD@{3}: checkout: moving from master to master@{2013-01-19}
eb64161 HEAD@{4}: pull: Fast-forward
4d6a183 HEAD@{5}: checkout: moving from 7e1ae4e7907f446d7d238741933509d4d64e0715
7e1ae4e HEAD@{6}: checkout: moving from 60299f452350c05d22e6bd703f1a7658112c171f
60299f4 HEAD@{7}: checkout: moving from 8e58a900f13132e0dcaa39ae980f7868184cbf65
8e58a90 HEAD@{8}: checkout: moving from 49f004a3d08ee52ee24334c07fc9d35c40480dbb
49f004a HEAD@{9}: checkout: moving from 4374fecebf215eb868beb881af8909922d45e764
4374fec HEAD@{10}: checkout: moving from 13a4a7e00c15986e07c48969f026afb2fe02f60
13a4a7e HEAD@{11}: checkout: moving from master to 13a4a7e00c15986e07c48969f026a
4d6a183 HEAD@{12}: reset: moving to HEAD@{20}
6eb9a8e HEAD@{13}: reset: moving to HEAD@{1}
0964917 HEAD@{14}: reset: moving to HEAD~1
6eb9a8e HEAD@{15}: reset: moving to HEAD~1
e6474e3 HEAD@{16}: reset: moving to HEAD~1
821fe87 HEAD@{17}: reset: moving to HEAD~1
04bd607 HEAD@{18}: reset: moving to HEAD~1
4173f0d HEAD@{19}: reset: moving to HEAD~1
6f15ad8 HEAD@{20}: reset: moving to HEAD~1
a847ccd HEAD@{21}: reset: moving to HEAD~1
498d2e7 HEAD@{22}: reset: moving to HEAD~1
fe2772d HEAD@{23}: reset: moving to HEAD~1
yes you can do this, open git console and put
git reflog
you will get list of your commits after that
git reset --hard "hash of commit which you need"
If you want your new HEAD to be 8d4f84a, then do
git reset --hard 8d4f84a
Resetting also works that direction.
git reflog
shows a history of all commit objects ever created. I guess the life span of a deleted commit object is 60 days. So if the commit is not older then you can probably do something like git cherry-pick your-commit-hash
. git show
can be used to inspect the code prior to cherry-picking it. Hope this helps.
下一篇: 如何在我执行git重置后恢复提交