if (FALSE) {
## Initialize a temporary repository
path <- tempfile(pattern="git2r-")
dir.create(path)
repo <- init(path)
# Configure a user
config(repo, user.name = "Alice", user.email = "alice@example.org")
## Create a file, add and commit
writeLines("Hello world!", file.path(path, "test-1.txt"))
add(repo, "test-1.txt")
commit_1 <- commit(repo, "Commit message")
## Change and stage the file
writeLines(c("Hello world!", "HELLO WORLD!"), file.path(path, "test-1.txt"))
add(repo, "test-1.txt")
status(repo)
## Unstage file
reset(repo, path = "test-1.txt")
status(repo)
## Make one more commit
add(repo, "test-1.txt")
commit(repo, "Next commit message")
## Create one more file
writeLines("Hello world!", file.path(path, "test-2.txt"))
## 'soft' reset to first commit and check status
reset(commit_1)
status(repo)
## 'mixed' reset to first commit and check status
commit(repo, "Next commit message")
reset(commit_1, "mixed")
status(repo)
## 'hard' reset to first commit and check status
add(repo, "test-1.txt")
commit(repo, "Next commit message")
reset(commit_1, "hard")
status(repo)
}
Run the code above in your browser using DataLab