How to print git history in rmarkdown?

I am writing an analysis report with rmarkdown and would like to have a "document version" section in which I would indicate different versions of the document and the changes made.

Instead of recording it manually, I thought about using the git history and inserted it automatically in the markdown document (formatting it in the table).

How can i do this? Is it possible?

+4
source share
2 answers

Install git2r, https://github.com/ropensci/git2r , then you can do things like:

> r = repository(".")
> cs = commits(r)
> cs[[1]]
[02cf9a0] 2017-02-02: uses Rcpp attributes instead of inline

, . .

> summary(cs[[1]])
Commit:  02cf9a0ff92d3f925b68853374640596530c90b5
Author:  barryrowlingson <b.rowlingson@gmail.com>
When:    2017-02-02 23:03:17

     uses Rcpp attributes instead of inline

11 files changed, 308 insertions, 151 deletions
DESCRIPTION           | -  0 +  2  in 2 hunks
NAMESPACE             | -  0 +  2  in 1 hunk
R/RcppExports.R       | -  0 + 23  in 1 hunk
R/auxfunctions.R      | -  1 +  1  in 1 hunk
R/skewt.r             | -  0 +  3  in 1 hunk
R/update_params.R     | -  1 +  1  in 1 hunk
R/update_params_cpp.R | -149 +  4  in 2 hunks
src/.gitignore        | -  0 +  3  in 1 hunk
src/RcppExports.cpp   | -  0 + 76  in 1 hunk
src/hello_world.cpp   | -  0 + 13  in 1 hunk
src/update_params.cpp | -  0 +180  in 1 hunk

, , .

> cs[[3]]@message
[1] "fix imports etc\n"
> cs[[3]]@committer@when
2017-01-20 23:26:20

, , @-notation . ...

:

> do.call(rbind,lapply(cs,function(cs){as(cs,"data.frame")}))

POSIXct, . !

+3

git pretty=format [1]

-

git log --reverse --pretty=format:'| %H | %s |'

- :

| a8d5defb511f1e44ddea21b42aec9b03ee768253 | initial commit |
| fdd9865e9cf01bd53c4f1dc106ee603b0a730f48 | fix tests |
| 10b58e8dd9cf0b9bebbb520408f0b342df613627 | add Dockerfile |
| d039004e8073a20b5d6eab1979c1afa213b78fa3 | update README.md |

1: https://git-scm.com/docs/pretty-formats

+2

Source: https://habr.com/ru/post/1668793/


All Articles