GIT – Restore Delete Files

I have written before about removing deleted files from a GIT repo. Today, I need to restore deleted files (on working copy) from the repo. This means that the files are in the repo, but are deleted in the working copy.

A simple scenario is that you are replacing some group of files by deleting the whole directory and replace with the new one. There may be other files that are not included in the new files but are still needed. When you run git status you will see that these files are deleted.

To restore accidentally deleted files is actually as easy as git checkout filename. However, if there are many files, we can improve it further. Note that this will only restore the deleted files into the working copy and the file will be coming from the repo. However, if the file is also deleted in the repo, that’s another story.

git checkout $(git ls-files -d)
This entry was posted in GIT and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *