Git development
 help / color / mirror / Atom feed
* Undo git-rm without commit?
@ 2008-03-26  6:17 Joe Fiorini
  2008-03-26  6:24 ` Mike Hommey
  2008-03-26  6:26 ` Jeff King
  0 siblings, 2 replies; 6+ messages in thread
From: Joe Fiorini @ 2008-03-26  6:17 UTC (permalink / raw)
  To: git

I hadn't done a git-commit yet, but I used git-rm thinking it would  
remove files that I had just added.  Instead, it deleted everything I  
had added from the disk.  Is there a way to undo this?  I'm doubtful,  
but would love to not have to rewrite what I was working on.

Thanks!
Joe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo git-rm without commit?
  2008-03-26  6:17 Undo git-rm without commit? Joe Fiorini
@ 2008-03-26  6:24 ` Mike Hommey
  2008-03-26  6:26 ` Jeff King
  1 sibling, 0 replies; 6+ messages in thread
From: Mike Hommey @ 2008-03-26  6:24 UTC (permalink / raw)
  To: Joe Fiorini; +Cc: git

On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:
> I hadn't done a git-commit yet, but I used git-rm thinking it would  
> remove files that I had just added.  Instead, it deleted everything I  
> had added from the disk.  Is there a way to undo this?  I'm doubtful,  
> but would love to not have to rewrite what I was working on.

Your best take would be to take a look at the unreachable loose objects
in your repository. One way to have a list of them would be to do a
git prune -n. Then you can look at the contents of each blob in those
with either git cat-file -p $sha1, or git show $sha1.

Mike

PS: What you wanted to use is git reset, not git rm.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo git-rm without commit?
  2008-03-26  6:17 Undo git-rm without commit? Joe Fiorini
  2008-03-26  6:24 ` Mike Hommey
@ 2008-03-26  6:26 ` Jeff King
  2008-03-26  6:38   ` Joe Fiorini
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2008-03-26  6:26 UTC (permalink / raw)
  To: Joe Fiorini; +Cc: git

On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:

> I hadn't done a git-commit yet, but I used git-rm thinking it would  
> remove files that I had just added.  Instead, it deleted everything I had 
> added from the disk.  Is there a way to undo this?  I'm doubtful, but 
> would love to not have to rewrite what I was working on.

If by "added" you mean "git add"ed, then yes. The file is hashed and the
blob is put in the object database during the add. Unfortunately,
nothing actually _refers_ to it, so you will have to pick it out
manually by its hash. Try:

  git fsck --lost-found

and then poke around .git/lost-found/other for your missing content.

As an aside, didn't git-rm warn you? While confirming that the command I
was giving you was correct, I did this:

  git init
  echo content >file
  git add file
  git rm file

and got:

  error: 'file' has changes staged in the index
  (use --cached to keep the file, or -f to force removal)

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo git-rm without commit?
  2008-03-26  6:26 ` Jeff King
@ 2008-03-26  6:38   ` Joe Fiorini
  2008-03-26  6:39     ` Jeff King
  2008-03-26  9:48     ` Matthieu Moy
  0 siblings, 2 replies; 6+ messages in thread
From: Joe Fiorini @ 2008-03-26  6:38 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Yeah, it warned me, I wasn't being careful enough.  I guess I didn't  
think it would remove from the working tree, just the repository.  My  
err for not reading the docs until _after_ the mistake.  Live &  
learn.  Thanks for the help, opening lost-found/other in TextMate  
solved my problem quickly!

Thanks again!
Joe

On Mar 26, 2008, at 2:26 AM, Jeff King wrote:

> On Wed, Mar 26, 2008 at 02:17:18AM -0400, Joe Fiorini wrote:
>
>> I hadn't done a git-commit yet, but I used git-rm thinking it would
>> remove files that I had just added.  Instead, it deleted everything  
>> I had
>> added from the disk.  Is there a way to undo this?  I'm doubtful, but
>> would love to not have to rewrite what I was working on.
>
> If by "added" you mean "git add"ed, then yes. The file is hashed and  
> the
> blob is put in the object database during the add. Unfortunately,
> nothing actually _refers_ to it, so you will have to pick it out
> manually by its hash. Try:
>
>  git fsck --lost-found
>
> and then poke around .git/lost-found/other for your missing content.
>
> As an aside, didn't git-rm warn you? While confirming that the  
> command I
> was giving you was correct, I did this:
>
>  git init
>  echo content >file
>  git add file
>  git rm file
>
> and got:
>
>  error: 'file' has changes staged in the index
>  (use --cached to keep the file, or -f to force removal)
>
> -Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo git-rm without commit?
  2008-03-26  6:38   ` Joe Fiorini
@ 2008-03-26  6:39     ` Jeff King
  2008-03-26  9:48     ` Matthieu Moy
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff King @ 2008-03-26  6:39 UTC (permalink / raw)
  To: Joe Fiorini; +Cc: git

On Wed, Mar 26, 2008 at 02:38:42AM -0400, Joe Fiorini wrote:

> Yeah, it warned me, I wasn't being careful enough.  I guess I didn't  
> think it would remove from the working tree, just the repository.  My err 
> for not reading the docs until _after_ the mistake.  Live & learn.  Thanks 
> for the help, opening lost-found/other in TextMate solved my problem 
> quickly!

OK, good. Just making sure there wasn't a bug in rm. ;)

-Peff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Undo git-rm without commit?
  2008-03-26  6:38   ` Joe Fiorini
  2008-03-26  6:39     ` Jeff King
@ 2008-03-26  9:48     ` Matthieu Moy
  1 sibling, 0 replies; 6+ messages in thread
From: Matthieu Moy @ 2008-03-26  9:48 UTC (permalink / raw)
  To: Joe Fiorini; +Cc: Jeff King, git

Joe Fiorini <joe@faithfulgeek.org> writes:

> Yeah, it warned me, I wasn't being careful enough.  I guess I didn't
> think it would remove from the working tree, just the repository.  My
> err for not reading the docs until _after_ the mistake.

Reading the error message would have done it also :-\.

>>  error: 'file' has changes staged in the index
>>  (use --cached to keep the file, or -f to force removal)
         ^^^^^^^^^^^^^^^^^^^^^^^^^

Good luck with lost+found, still !

-- 
Matthieu

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-03-26  9:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-26  6:17 Undo git-rm without commit? Joe Fiorini
2008-03-26  6:24 ` Mike Hommey
2008-03-26  6:26 ` Jeff King
2008-03-26  6:38   ` Joe Fiorini
2008-03-26  6:39     ` Jeff King
2008-03-26  9:48     ` Matthieu Moy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox