git-revision: Identify commits like a human

Description Usage Arguments Value git_revision git_revision_exists References Examples

Description

Retrieve the SHA-1 for a specific commit via a human-friendly description, like

Convenience wrapper around git2r::revparse_single(), which implements functionality from git rev-parse.

Usage

1
2
3
git_revision(rev = "HEAD", repo = ".")

git_revision_exists(rev, repo = ".")

Arguments

rev

Target commit, as a revision string, e.g. HEAD^, branchname, SHA-1 or a leading substring thereof.

repo

Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo.

Value

SHA of the commit. The when attribute holds the commit time as POSIXct. An excerpt of the commit message is in the msg_start attribute.

git_revision

If called with no arguments, this returns SHA for HEAD of repo associated with current working directory.

git_revision_exists

Tests if rev can be resolved to a specific commit.

References

Revision Selection from the Pro Git book by Scott Chacon and Ben Straub

Specifying revisions section of the git-rev-parse man page

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
repo <- git_init(tempfile("githug-revisions-"))
owd <- setwd(repo)

## no commits --> HEAD cannot be resolved
git_revision_exists("HEAD")
## Not run: 
git_revision()

## End(Not run)

## commit and ... now HEAD exists
write("Well, we're not in the middle of nowhere,", "nowhere.txt")
git_commit(all = TRUE, message = "1ouise: not in the middle of nowhere")
git_revision()
git_revision_exists("HEAD")

## make a new commit then ask for parent of HEAD
write("but we can see it from here.", "nowhere.txt", append = TRUE)
git_commit(all = TRUE, message = "louise: but can see it")
git_revision("HEAD^")

## create a new branch and find out what it points at
git_switch("newbranch", create = TRUE)
git_revision("newbranch")

setwd(owd)

jennybc/githug documentation built on May 19, 2019, 5:05 a.m.