| git_revert | R Documentation |
Applies the inverse of the changes introduced by a given commit, equivalent
to git revert <commit>. The commit must be reachable from the current HEAD.
git_revert(ref, commit = TRUE, ..., repo = ".")
ref |
revision string with a branch/tag/commit value |
commit |
if |
... |
parameters passed to |
repo |
The path to the git repository. If the directory is not a
repository, parent directories are considered (see |
By default, a new revert commit is created immediately. Set commit = FALSE
to only stage the reverted changes without committing, leaving you free to
amend or combine them before calling git_commit().
The SHA of the new revert commit (invisibly), or NULL when
commit = FALSE.
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_restore(),
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)
writeLines("world", file.path(repo, "hello.txt"))
git_add("hello.txt", repo = repo)
bad_commit <- git_commit("Second commit", repo = repo)
# Default: revert and commit with an auto-generated message
git_revert(bad_commit, repo = repo)
git_log(repo = repo)
# Revert with a custom message
writeLines("oops", file.path(repo, "hello.txt"))
git_add("hello.txt", repo = repo)
bad_commit2 <- git_commit("Third commit", repo = repo)
git_revert(bad_commit2, message = "Undo third commit\n", repo = repo)
git_log(repo = repo)
# Stage the revert without committing
writeLines("again", file.path(repo, "hello.txt"))
git_add("hello.txt", repo = repo)
bad_commit3 <- git_commit("Fourth commit", repo = repo)
git_revert(bad_commit3, commit = FALSE, repo = repo)
git_status(repo = repo)
unlink(repo, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.