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.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • E-mail this story to a friend!
  • HackerNews
  • Reddit
  • StumbleUpon
  • Twitter

Post a Comment