Last Updated: December 03, 2019
·
208
· pwpearson

Bash function to restore a deleted file in a Git repository

Add to .bashrc or .bashprofile
```
function git
undeletefile () {
if [ $# -eq 0 ]; then
echo "Usage: git
undelete_file <filepath>";
exit 1;
fi

git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
}
```