Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I recover my commit after I did a git reset --hard head?

Tags:

git

heroku

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
like image 498
user1426594 Avatar asked Feb 01 '13 23:02

user1426594


People also ask

Can I undo git reset head?

So, to undo the reset, run git reset HEAD@{1} (or git reset d27924e ). If, on the other hand, you've run some other commands since then that update HEAD, the commit you want won't be at the top of the list, and you'll need to search through the reflog .

Do we need to commit after git reset hard?

git reset hard and pushWhen you git reset local commits, those commits don't disappear. After the push, when we look at the commit history on GitHub, we notice there are only four commits, the server-side commit that created the GitHub repository, and the three local commits that we published.


2 Answers

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"
like image 153
Abbath Avatar answered Oct 31 '22 15:10

Abbath


If you want your new HEAD to be 8d4f84a, then do

git reset --hard 8d4f84a

Resetting also works that direction.

like image 29
Kalle Pokki Avatar answered Oct 31 '22 15:10

Kalle Pokki