Recover committed (deleted) file in Git
What if, just suppose, you deleted a file in error, made the commit to Git, then several commits later you realise you needed the file all along. How do you get it back?
Well, you find the last commit for that file and then checkout the file with the revision number. In just a few lines then…
Robs-iMac:repo rl$ file='app/views/previously_deleted.html.haml'
Robs-iMac:repo rl$ echo $file
app/views/previously_deleted.html.haml
Robs-iMac:repo rl$ git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"