threads / discuss / 12768

How to undo git-rm?

Subject: How to undo git-rm?

## tl;dr

5 messages between Mar 18, 2008 and Mar 20, 2008.

replies: 4people: 4as markdown or json

Neil Schemenauer· Mar 18, 2008, 23:04 UTC · lore
Hi,

This seemingly simple operation has me stumped. I removed something from my try using "git rm" and now I want it back. With SVN I would use "svn cat <path> > <path>". After some searching around, I though git-cat-file would do the trick. Alas, it appears as though it looks up the SHA for the path in the index and so it too fails.

  Neil
Junio C Hamano· Mar 20, 2008, 00:24 UTC · re: Neil Schemenauer · lore

Re: How to undo git-rm?

Neil Schemenauer <nas@arctrix.com> writes:
Show 5 quoted lines
> This seemingly simple operation has me stumped.  I removed something
> from my try using "git rm" and now I want it back.  With SVN I would
> use "svn cat <path> > <path>".  After some searching around, I
> though git-cat-file would do the trick.  Alas, it appears as though
> it looks up the SHA for the path in the index and so it too fails.
"git checkout HEAD -- that-path"?
Jakub Narebski· Mar 20, 2008, 00:49 UTC · re: Neil Schemenauer · lore

Re: How to undo git-rm?

Neil Schemenauer <nas@arctrix.com> writes:
Show 7 quoted lines
> Hi,
> 
> This seemingly simple operation has me stumped.  I removed something
> from my try using "git rm" and now I want it back.  With SVN I would
> use "svn cat <path> > <path>".  After some searching around, I
> though git-cat-file would do the trick.  Alas, it appears as though
> it looks up the SHA for the path in the index and so it too fails.
Direct equivalent would be
  $ git show HEAD:<path> > <path>   # from last commit
  $ git show :<path>     > <path>   # from index
but actually you would probably use
  $ git checkout -- <path>
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Elijah Newren· Mar 20, 2008, 02:53 UTC · re: Neil Schemenauer · lore

Re: How to undo git-rm?

On Tue, Mar 18, 2008 at 5:04 PM, Neil Schemenauer <nas@arctrix.com> wrote:
Show 7 quoted lines
> Hi,
>
>  This seemingly simple operation has me stumped.  I removed something
>  from my try using "git rm" and now I want it back.  With SVN I would
>  use "svn cat <path> > <path>".  After some searching around, I
>  though git-cat-file would do the trick.  Alas, it appears as though
>  it looks up the SHA for the path in the index and so it too fails.
Try
  git checkout HEAD eg
or
  git show HEAD:<path> > <path>
Elijah Newren· Mar 20, 2008, 02:54 UTC · re: Elijah Newren · lore

Re: How to undo git-rm?

On Wed, Mar 19, 2008 at 8:53 PM, Elijah Newren <newren@gmail.com> wrote:
Show 11 quoted lines
> On Tue, Mar 18, 2008 at 5:04 PM, Neil Schemenauer <nas@arctrix.com> wrote:
>  > Hi,
>  >
>  >  This seemingly simple operation has me stumped.  I removed something
>  >  from my try using "git rm" and now I want it back.  With SVN I would
>  >  use "svn cat <path> > <path>".  After some searching around, I
>  >  though git-cat-file would do the trick.  Alas, it appears as though
>  >  it looks up the SHA for the path in the index and so it too fails.
>
>  Try
>   git checkout HEAD eg
doh, that should be
  git checkout HEAD <path>
of course.
>  or
>   git show HEAD:<path> > <path>

← back to recent threads