-2

I did a git rm somefile and I wish to just undo it. Is there a way to do that?

In other words I just want to restore that one file and everything else should stay the same.

Ole
  • 41,793
  • 59
  • 191
  • 359
  • 1
    Note that if you type `git status` with no switches, it will show a message telling you exactly how to do this – M.M May 06 '18 at 21:43

2 Answers2

2

You can just do this, If you have not committed yet.

git checkout somefile

If you have already committed, then you can only get the file from previous commit. That can be done by:

git checkout HEAD~ somefile
0

git checkout HEAD path/to/file

Ole
  • 41,793
  • 59
  • 191
  • 359