Recover files from git after deletion is committed
As I work with git, I have occasionally deleted files that I later end up needing. You can restore the files, but it’s not an intuitive process.
First, I looked at the output of git log to find the commit that I deleted the files with.
Then I ran:
[text]
git diff –diff-filter=D –name-only HEAD@{‘7 days ago’} | \
grep -v ^doc | perl -ne ‘chomp;
print "git show e2ae03f14ce81a3e24ec6cbe2e73767f4c6fed1b — $_ > $_\n";’ | sh
[/text]
This restored all the files I deleted that did not start with doc.
These files show up as diff files, so you may have to remove the “- ” at the beginning of the lines and commit messages. But hey, it’s better than not having the files you need.