Git: Restore deleted file

29Apr14

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.

About these ads


Follow

Get every new post delivered to your Inbox.

Join 68 other followers

%d bloggers like this: