How to undelete a file previously deleted in git's history?

Tobias Kienzler picture Tobias Kienzler · Jun 30, 2010 · Viewed 30.4k times · Source

Using Chris's answer on another question I could prepend a snapshot-history to my git repository. Since one of the files is not part of my history but only in the snapshots, the first original commit now also contains the deletion of this file. How can I undo that?

At first I thought this was the opposite of How do I remove sensitive files from git’s history, but actually I don't want to insert a file into history but just remove the deletion from history.

Answer

kubi picture kubi · Jun 30, 2010
git checkout <commit> <filename>