| git_restore | R Documentation |
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.
git_restore(path, ref = "HEAD", repo = ".")
path |
character vector with file paths to restore, relative to the
repository root. Use |
ref |
revision string with a branch/tag/commit to restore from.
Defaults to |
repo |
The path to the git repository. If the directory is not a
repository, parent directories are considered (see |
Invisibly, the git_status() after restoring.
Other git:
git_archive,
git_branch(),
git_commit(),
git_config(),
git_diff(),
git_fetch(),
git_history,
git_ignore,
git_merge(),
git_rebase(),
git_remote,
git_repo,
git_reset(),
git_revert(),
git_signature(),
git_stash,
git_tag,
git_worktree
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.