Git: Restore deleted file


Here’s a handy alias I nabbed from somewhere, which restores a file accidentally deleted by a commit.


git config --global alias.restore '!f() { git checkout $(git rev-list -n 1 HEAD -- $1)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- $1)~1 | grep '^D' | cut -f 2); }; f'


In future, just use git restore myfile.ext to restore your deleted file.


Get every new post delivered to your Inbox.

Join 77 other followers

%d bloggers like this: