Jin*_*cko 3 git r sha rstudio r-markdown
有没有办法从R获取当前GIT提交的SHA?我需要通过函数调用(而不是硬字符串)来访问它。
我已将GIT用作版本控制系统进行分析,并希望在中间报告的脚注上打印SHA(我的工作草案以pdf格式保存,他们自己活着,而看着他们的情况并不能立即看出来。它们生成的那一刻;这会造成可再现性问题)。
供参考:我正在通过R Studio使用R 3.4.1,并通过r markdown创建报告。
安装git2r包,然后:
> r = git2r::revparse_single(repository(path),"HEAD")
> r@sha
[1] "515e0160237149b534ea0b105c03584d72c6173c"
Run Code Online (Sandbox Code Playgroud)
它还在返回对象的其他插槽中为您提供有关提交的其他一些信息。
> r@author
name: Barry Rowlingson
email: b.rowlingson@example.com
when: 2017-09-17 22:27:28
Run Code Online (Sandbox Code Playgroud)
您将需要git rev-parse按以下说明调用命令:如何在Git中检索当前提交的哈希值?
您可以使用system():
https://stat.ethz.ch/R-manual/R-devel/library/base/html/system.html
把它放在一起:
system("git rev-parse HEAD", intern=TRUE)
Run Code Online (Sandbox Code Playgroud)