if (FALSE) { # interactive()
repo <- file.path(tempdir(), "myrepo")
git_init(repo)
# Set a user if no default
if (!user_is_configured()) {
git_config_set("user.name", "Jerry")
git_config_set("user.email", "jerry@gmail.com")
}
writeLines("hello", file.path(repo, "hello.txt"))
git_add("hello.txt", repo = repo)
git_commit("First commit", repo = repo)
# Modify the file, then restore it from HEAD
writeLines("oops", file.path(repo, "hello.txt"))
git_restore("hello.txt", repo = repo)
readLines(file.path(repo, "hello.txt")) # "hello"
unlink(repo, recursive = TRUE)
}
Run the code above in your browser using DataLab