In my dotfiles I have the following function which works:
function undelete {
git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
}
…which I use like this:
$ undelete /path/to/deleted/file.txt
I'd like to scope this command since it's a git command.
How do I create a git alias so that I can use this git alias command?
$ git undelete /path/to/deleted/file.txt
Here are two, of my attempts which do not work:
git config --global alias.undelete "!f() { git checkout $(git rev-list -n 1 HEAD -- $1)^ -- $1; }; f"
git config --global alias.undelete "!sh -c 'git checkout $(git rev-list -n 1 HEAD -- $1)^ -- $1' -"
'\''
to embed a singlequote in a singlequoted string. – Rhombohedral