5

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
Zombo
  • 1
  • 62
  • 391
  • 407
user1426594
  • 125
  • 1
  • 6
  • take a look at the [reflog](http://www.kernel.org/pub/software/scm/git/docs/git-reflog.html) – Ricardo Souza Feb 01 '13 at 23:34
  • Check out these two answers: * [Undo git reset --hard](http://stackoverflow.com/a/7376959/2942) * [Undoing a git reset --hard HEAD~1](http://stackoverflow.com/a/21778/2942) – friism Feb 01 '13 at 23:42
  • just do a checkout on the commit you want from the reflog and you have all your work back. Unless you have cleaned your repo. – Ricardo Souza Feb 01 '13 at 23:46
  • All those reflogs are for December 7th and back. – user1426594 Feb 02 '13 at 00:15
  • Why can't you clone from heroku? `git clone git@heroku.com:projectname.git` seems to work fine here. What output do you get doing so for your project? – cjc343 Feb 02 '13 at 00:58
  • When I clone from heroku, I get the latest release which has commits from beginning to December 7th only. I did a git push -f which overrode my last release. I rolled back 1 release using Heroku, but Heroku does not let you clone the rolled back release. – user1426594 Feb 02 '13 at 01:08
  • Ah, that's unfortunate. Still, they must have a copy of the release you rolled back to somewhere. It can't hurt to contact them. Worst case you're in the same state you are now. – cjc343 Feb 02 '13 at 01:14
  • try `git reflog master`. Your reflog should have a lot of entries – do you only get those 20 entries? And did you do any call to `git gc`? – Chronial Feb 02 '13 at 03:32
  • Yeah I only have those 24 entries. I'm really not sure what even happened...I'm sort of new to Git. – user1426594 Feb 02 '13 at 15:16

3 Answers3

6

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"
Abbath
  • 1,002
  • 13
  • 30
3

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

git reset --hard 8d4f84a

Resetting also works that direction.

Kalle Pokki
  • 4,939
  • 2
  • 17
  • 18
  • Fatal: ambiguous argument '8d4f84a': unknown revision or path not in the working tree. – user1426594 Feb 02 '13 at 15:15
  • I force pushed a bad copy of the repo which made it so I couldn't find that commit. I contacted Heroku support via Twitter and got the issue resolved. – user1426594 Feb 12 '13 at 22:46
3

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.

Gaurav Agarwal
  • 14,664
  • 4
  • 29
  • 41