path <- path.expand("~/GitHub/packages/glitter")

My long lost file from the working directory is R/destroy.R. I then get the commit history of that file using the full path.

list_file_commits(file = "R/destroy.R",
                  path = path)
#> No response present

By default, this file is recovered using the most recent commit automatically.

I first check to make sure this file does not already exist.

file.exists(path_to_file)
#> [1] FALSE

I recover the lost file:

recover_lost_file(file = path_to_file)

QA to make sure that the file now is present:

file.exists(path_to_file)
#> [1] FALSE

However, a version of the file from a commit before the most recent one is desired, the SHA can be entered to retrieve that version instead.

file.remove(path_to_file)
#> [1] FALSE
recover_lost_file(file = path_to_file, 
                  sha = "aa448c7de4ead65905dfb3133ec42ac8a6f332fc")
file.exists(path_to_file)
#> [1] FALSE