blame: Get blame for file

Description Usage Arguments Value Examples

View source: R/blame.R

Description

Get blame for file

Usage

1
blame(repo = ".", path = NULL)

Arguments

repo

a path to a repository or a git_repository object. Default is '.'

path

Path to the file to consider

Value

git_blame object with the following entries:

path

The path to the file of the blame

hunks

List of blame hunks

repo

The git_repository that contains the file

lines_in_hunk

The number of lines in this hunk

final_commit_id

The sha of the commit where this line was last changed

final_start_line_number

The 1-based line number where this hunk begins, in the final version of the file

final_signature

Final committer

orig_commit_id

The sha of the commit where this hunk was found. This will usually be the same as 'final_commit_id'.

orig_start_line_number

The 1-based line number where this hunk begins in the file named by 'orig_path' in the commit specified by 'orig_commit_id'.

orig_signature

Origin committer

orig_path

The path to the file where this hunk originated, as of the commit specified by 'orig_commit_id'

boundary

TRUE iff the hunk has been tracked to a boundary commit.

repo

The git_repository object that contains the blame hunk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
## Initialize a temporary repository
path <- tempfile(pattern="git2r-")
dir.create(path)
repo <- init(path)

## Create a first user and commit a file
config(repo, user.name = "Alice", user.email = "alice@example.org")
writeLines("Hello world!", file.path(path, "example.txt"))
add(repo, "example.txt")
commit(repo, "First commit message")

## Create a second user and change the file
config(repo, user.name = "Bob", user.email = "bob@example.org")
writeLines(c("Hello world!", "HELLO WORLD!", "HOLA"),
           file.path(path, "example.txt"))
add(repo, "example.txt")
commit(repo, "Second commit message")

## Check blame
blame(repo, "example.txt")

## End(Not run)

Example output

[306f020] 2020-05-22: First commit message
[9908ea4] 2020-05-22: Second commit message
$path
[1] "example.txt"

$hunks
$hunks[[1]]
$lines_in_hunk
[1] 1

$final_commit_id
[1] "306f020acc888505dc268d806a5dad084ff2fc01"

$final_start_line_number
[1] 1

$final_signature
name:  Alice
email: alice@example.org
when:  2020-05-22 14:37:17

$orig_commit_id
[1] "306f020acc888505dc268d806a5dad084ff2fc01"

$orig_start_line_number
[1] 1

$orig_signature
name:  Alice
email: alice@example.org
when:  2020-05-22 14:37:17

$orig_path
[1] "example.txt"

$boundary
[1] TRUE

$repo
Local:    master /work/tmp/tmp/Rtmp3xPEdD/git2r-ddd2fa0b7d1
Head:     [9908ea4] 2020-05-22: Second commit message

attr(,"class")
[1] "git_blame_hunk"

$hunks[[2]]
$lines_in_hunk
[1] 2

$final_commit_id
[1] "9908ea4307a8de346d254fee3f2742769f60d83a"

$final_start_line_number
[1] 2

$final_signature
name:  Bob
email: bob@example.org
when:  2020-05-22 14:37:17

$orig_commit_id
[1] "9908ea4307a8de346d254fee3f2742769f60d83a"

$orig_start_line_number
[1] 2

$orig_signature
name:  Bob
email: bob@example.org
when:  2020-05-22 14:37:17

$orig_path
[1] "example.txt"

$boundary
[1] FALSE

$repo
Local:    master /work/tmp/tmp/Rtmp3xPEdD/git2r-ddd2fa0b7d1
Head:     [9908ea4] 2020-05-22: Second commit message

attr(,"class")
[1] "git_blame_hunk"


$repo
Local:    master /work/tmp/tmp/Rtmp3xPEdD/git2r-ddd2fa0b7d1
Head:     [9908ea4] 2020-05-22: Second commit message

attr(,"class")
[1] "git_blame"

git2r documentation built on Nov. 22, 2021, 9:08 a.m.

Related to blame in git2r...