# Git screwup with reset

3 messages from 2009-05-18 to 2009-05-18. Participants: jake varghese, Shawn O. Pearce, Sverre Rabbelier.
Thread: https://gitlist.dev/t/19404

## jake varghese, 2009-05-18 14:58

Subject: Git screwup with reset
Message-ID: <9D569322-6A7B-4447-962C-0C740945E227@orgsync.com>
URL: https://gitlist.dev/e/9D569322-6A7B-4447-962C-0C740945E227%40orgsync.com

```
Hi All,

I really screwed up.  I had about 2 weeks worth of code I was working  
on that got reset right out before commit.

Here's what happened.

1.  I coded for 2 weeks and didnt commit or add anything (yes, i  
know, real stupid)
2.  I was attempting to commit today and added the files.
3.  I realized a couple of files were added that i didnt want and  
werent being matched to the gitignore because i spelled them wrong.   
I fixed the gitignore file but the files still showed up, Im guessing  
because i used "git add ." before.
4.  Then i ran git reset --hard because i just wanted to undo the  
add.  Clearly this was where everything fell apart.
5.  I lost 2 weeks worth of code.

That's basically how it happened.


When I run git fsck --lost-found i get a whole bunch of dangling  
objects.  If I run git show on those objects it shows me the code  
that was lost.  Anyone know of a way to get this stuff back.  I tried  
rebasing and merging and neither worked.




Thanks in advance,


Jake Varghese
OrgSync Inc.
866.ORG.SYNC
jake@orgsync.com
www.orgsync.com

```

## Shawn O. Pearce, 2009-05-18 15:08

Subject: Re: Git screwup with reset
Message-ID: <20090518150840.GJ30527@spearce.org>
URL: https://gitlist.dev/e/20090518150840.GJ30527%40spearce.org
In-Reply-To: <9D569322-6A7B-4447-962C-0C740945E227@orgsync.com>

```
jake varghese <jake@orgsync.com> wrote:
> When I run git fsck --lost-found i get a whole bunch of dangling  
> objects.  If I run git show on those objects it shows me the code that 
> was lost.  Anyone know of a way to get this stuff back.  I tried  
> rebasing and merging and neither worked.

For each of those dangling blobs:

  git cat-file blob $sha1 >$path

where you need to manually figure out the relationship between
$sha1 and the local $path within your project.  Git doesn't have
that relationship data, because you never made a commit.

Oh, and next time, commit like every hour, or more frequently than
that.  At worst, you'll need to do a "git merge --squash" near the
end to flatten out your silly "save my work" checkpoints and draft
a more useful commit message for your coworkers.  But at least you
lose less when you have a "git reset --hard" fat finger accident.

-- 
Shawn.

```

## Sverre Rabbelier, 2009-05-18 15:11

Subject: Re: Git screwup with reset
Message-ID: <fabb9a1e0905180811r6e408ce5ged65ddfb3846111c@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0905180811r6e408ce5ged65ddfb3846111c%40mail.gmail.com
In-Reply-To: <9D569322-6A7B-4447-962C-0C740945E227@orgsync.com>

```
Heya,

On Mon, May 18, 2009 at 16:58, jake varghese <jake@orgsync.com> wrote:
>  Anyone know of a way to get this stuff back.

Make a backup copy of that .git directory, so that whatever you do you
won't lose that work ;). Also, the reason you can't merge or rebase
that hash is because it's the hash of a tree or a blob, not a commit.
You can use git commit-tree [0] to create a commit from your lost
tree, but that works only if you have a tree (for just a blob you can
use git cat-file [1])

[0] http://www.kernel.org/pub/software/scm/git/docs/git-commit-tree.html
[1] http://kernel.org/pub/software/scm/git/docs/git-cat-file.html

-- 
Cheers,

Sverre Rabbelier

```
