% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/restore.R
\name{git_restore}
\alias{git_restore}
\title{Restore working tree files}
\usage{
git_restore(path, ref = "HEAD", repo = ".")
}
\arguments{
\item{path}{character vector with file paths to restore, relative to the
repository root. Use \code{"."} to restore all tracked files.}

\item{ref}{revision string with a branch/tag/commit to restore from.
Defaults to \code{"HEAD"}.}

\item{repo}{The path to the git repository. If the directory is not a
repository, parent directories are considered (see \code{\link[=git_find]{git_find()}}). To disable
this search, provide the filepath protected with \code{\link[=I]{I()}}. When using this
parameter, always explicitly call by name (i.e. \verb{repo = }) because future
versions of gert may have additional parameters.}
}
\value{
Invisibly, the \code{\link[=git_status]{git_status()}} after restoring.
}
\description{
Restores specified paths in the working tree from a given ref, equivalent
to \verb{git restore --source=<ref> <path>} (or the older
\verb{git checkout <ref> -- <path>}). The ref must be reachable from the
current HEAD. By default restores from HEAD, discarding any local
modifications.
}
\examples{
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf}
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)
\dontshow{\}) # examplesIf}
}
\seealso{
Other git:
\code{\link{git_archive}},
\code{\link[=git_branch]{git_branch()}},
\code{\link[=git_commit]{git_commit()}},
\code{\link[=git_config]{git_config()}},
\code{\link[=git_diff]{git_diff()}},
\code{\link[=git_fetch]{git_fetch()}},
\code{\link{git_history}},
\code{\link{git_ignore}},
\code{\link[=git_merge]{git_merge()}},
\code{\link[=git_rebase]{git_rebase()}},
\code{\link{git_remote}},
\code{\link{git_repo}},
\code{\link[=git_reset]{git_reset()}},
\code{\link[=git_revert]{git_revert()}},
\code{\link[=git_signature]{git_signature()}},
\code{\link{git_stash}},
\code{\link{git_tag}},
\code{\link{git_worktree}}
}
\concept{git}
