How to Recover a List of Files with Git
This is a piece of information I am posting for my own convenience, but that may be of use to other people using Git.
I use git to keep my local files. Not only programming files, but also all types of information, including blog entries and other miscellaneous data.
Sometimes I delete or move a whole directory, and wish to recover it later.
The recipe is simple, but easy to forget because I rarely use it:
git ls-files -d | xargs git checkout -- |
To explain this, notice that git ls-files -d just list deleted files. Then, xargs will feed these names to git checkout --, which is responsible for restoring the file.
Similar Posts:
About the Author
Carlos Oliveira holds a PhD in Systems Engineering and Optimization from University of Florida. He works as a software engineer, with more than 10 years of experience in developing high performance, commercial and scientific applications in C++, Java, and Objective-C. His most Recent Book is Practical C++ Financial Programming.