Restores specified paths in the working tree from a given ref, equivalent
to git restore --source=<ref> <path> (or the older
git checkout <ref> -- <path>). The ref must be reachable from the
current HEAD. By default restores from HEAD, discarding any local
modifications.
Arguments
- path
character vector with file paths to restore, relative to the repository root. Use
"."to restore all tracked files.- ref
revision string with a branch/tag/commit to restore from. Defaults to
"HEAD".- repo
The path to the git repository. If the directory is not a repository, parent directories are considered (see
git_find()). To disable this search, provide the filepath protected withI(). When using this parameter, always explicitly call by name (i.e.repo =) because future versions of gert may have additional parameters.
Value
Invisibly, the git_status() after restoring.
Examples
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)
}
