Git saved my day – restore accidentally deleted files using Git version control

Note: This post was originally posted on my former blog Serpensalbus.com on July 24th, 2008 (and it was by far the most popular one).

Today I somehow accidentally deleted some source code files in Intellij IDEA. I don’t know how this exactly happened – I must have clicked the wrong menu item.

Because I’m using Git for version control I could recover the files immediately (see below).

To show deleted files use the command:

git ls-files -d

To restore the deleted files use:

git ls-files -d | xargs git checkout –

The source for this information can be found here:

http://lists.freedesktop.org/archives/xorg/2006-October/018572.html

So, thanks Git!

Lars Fischer

Read more posts by this author.

Subscribe to Lars-Fischer.me

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!
comments powered by Disqus