[英]Read repository source code files through the Ruby git gem?
我想通过git gem访问存储库的源代码。 我的目标是浏览源代码文件并阅读其内容。
从示例中我不清楚我是如何做到这一点的? 我觉得我需要使用Git.open
,如下所示:
g = Git.open(working_dir, :log => Logger.new(STDOUT))
但是我不清楚working_dir
是什么。 如果我要定位github.com/ruby-git/ruby-git项目,有很多方法可以引用它。 它可以是以下任何一种:
git@github.com:ruby-git/ruby-git.git
https://github.com/ruby-git/ruby-git.git
https://github.com/ruby-git/ruby-git
如果您知道我如何从存储库中读取源代码文件,请告诉我。
working_dir
是使用Git的项目目录。
说您的项目位于/home/john_smith_1976/awesome_project
文件夹中。
在这种情况下使用
require 'git'
g = Git.open('/home/john_smith_1976/awesome_project')
之后,例如你可以使用g.grep('some_code')
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.