Skip to contentSkip to conversation

How to undo git-rm?

DISCUSSION Neil Schemenauer 4 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw
Quoted 7 lines · Neil Schemenauer

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>

#2 lore raw
Quoted 11 lines · Elijah Newren
Quoted 7 lines · Neil Schemenauer

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.

Quoted 2 lines

or
git show HEAD:<path> > <path>

#3 lore raw
In reply to Neil Schemenauer
Quoted 5 lines · Neil Schemenauer

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

#4 lore raw
In reply to Neil Schemenauer
Quoted 7 lines · Neil Schemenauer

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>
Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git