{"thread":{"id":"19404","subject":"Git screwup with reset","startedAt":"2009-05-18T14:58:11Z","lastAt":"2009-05-18T15:11:38Z","messageCount":3,"participants":["jake varghese","Shawn O. Pearce","Sverre Rabbelier"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114182","messageId":"9D569322-6A7B-4447-962C-0C740945E227@orgsync.com","threadId":"19404","inReplyTo":null,"subject":"Git screwup with reset","fromName":"jake varghese","fromEmail":"jake@orgsync.com","sentAt":"2009-05-18T14:58:11Z","receivedAt":"2009-05-18T14:58:11Z","isPatch":false,"sender":{"key":"jake@orgsync.com","avatar":null},"body":"Hi All,\n\nI really screwed up.  I had about 2 weeks worth of code I was working  \non that got reset right out before commit.\n\nHere's what happened.\n\n1.  I coded for 2 weeks and didnt commit or add anything (yes, i  \nknow, real stupid)\n2.  I was attempting to commit today and added the files.\n3.  I realized a couple of files were added that i didnt want and  \nwerent being matched to the gitignore because i spelled them wrong.   \nI fixed the gitignore file but the files still showed up, Im guessing  \nbecause i used \"git add .\" before.\n4.  Then i ran git reset --hard because i just wanted to undo the  \nadd.  Clearly this was where everything fell apart.\n5.  I lost 2 weeks worth of code.\n\nThat's basically how it happened.\n\n\nWhen I run git fsck --lost-found i get a whole bunch of dangling  \nobjects.  If I run git show on those objects it shows me the code  \nthat was lost.  Anyone know of a way to get this stuff back.  I tried  \nrebasing and merging and neither worked.\n\n\n\n\nThanks in advance,\n\n\nJake Varghese\nOrgSync Inc.\n866.ORG.SYNC\njake@orgsync.com\nwww.orgsync.com\n"},{"id":"114183","messageId":"20090518150840.GJ30527@spearce.org","threadId":"19404","inReplyTo":"9D569322-6A7B-4447-962C-0C740945E227@orgsync.com","subject":"Re: Git screwup with reset","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-05-18T15:08:40Z","receivedAt":"2009-05-18T15:08:40Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"jake varghese <jake@orgsync.com> wrote:\n> When I run git fsck --lost-found i get a whole bunch of dangling  \n> objects.  If I run git show on those objects it shows me the code that \n> was lost.  Anyone know of a way to get this stuff back.  I tried  \n> rebasing and merging and neither worked.\n\nFor each of those dangling blobs:\n\n  git cat-file blob $sha1 >$path\n\nwhere you need to manually figure out the relationship between\n$sha1 and the local $path within your project.  Git doesn't have\nthat relationship data, because you never made a commit.\n\nOh, and next time, commit like every hour, or more frequently than\nthat.  At worst, you'll need to do a \"git merge --squash\" near the\nend to flatten out your silly \"save my work\" checkpoints and draft\na more useful commit message for your coworkers.  But at least you\nlose less when you have a \"git reset --hard\" fat finger accident.\n\n-- \nShawn.\n"},{"id":"114184","messageId":"fabb9a1e0905180811r6e408ce5ged65ddfb3846111c@mail.gmail.com","threadId":"19404","inReplyTo":"9D569322-6A7B-4447-962C-0C740945E227@orgsync.com","subject":"Re: Git screwup with reset","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2009-05-18T15:11:38Z","receivedAt":"2009-05-18T15:11:38Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Mon, May 18, 2009 at 16:58, jake varghese <jake@orgsync.com> wrote:\n>  Anyone know of a way to get this stuff back.\n\nMake a backup copy of that .git directory, so that whatever you do you\nwon't lose that work ;). Also, the reason you can't merge or rebase\nthat hash is because it's the hash of a tree or a blob, not a commit.\nYou can use git commit-tree [0] to create a commit from your lost\ntree, but that works only if you have a tree (for just a blob you can\nuse git cat-file [1])\n\n[0] http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html\n[1] http://kernel.org/pub/software/scm/git/docs/git-cat-file.html\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}