Undo git-rm without commit?

Previous thread: Re: [RFC/PATCH 4/4] Introduce fast forward option only by Sverre Hvammen Johansen on Tuesday, March 25, 2008 - 11:59 pm. (1 message)

Next thread: none
To: <git@...>
Date: Wednesday, March 26, 2008 - 2:17 am

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
--

To: Joe Fiorini <joe@...>
Cc: <git@...>
Date: Wednesday, March 26, 2008 - 2:26 am

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
--

To: Jeff King <peff@...>
Cc: <git@...>
Date: Wednesday, March 26, 2008 - 2:38 am

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

--

To: Joe Fiorini <joe@...>
Cc: Jeff King <peff@...>, <git@...>
Date: Wednesday, March 26, 2008 - 5:48 am

^^^^^^^^^^^^^^^^^^^^^^^^^

Good luck with lost+found, still !

--
Matthieu
--

To: Joe Fiorini <joe@...>
Cc: <git@...>
Date: Wednesday, March 26, 2008 - 2:39 am

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

-Peff
--

To: Joe Fiorini <joe@...>
Cc: <git@...>
Date: Wednesday, March 26, 2008 - 2:24 am

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.
--

Previous thread: Re: [RFC/PATCH 4/4] Introduce fast forward option only by Sverre Hvammen Johansen on Tuesday, March 25, 2008 - 11:59 pm. (1 message)

Next thread: none