Ruby/Git是一个Ruby库可用来创建、操作Git资料库。它是通过封装了系统命令调用的方式实现的。
示例代码:
require'rubygems'require'git'g=Git.open(working_dir,:log=>Logger.new(STDOUT))g.indexg.index.readable?g.index.writable?g.repog.dirg.log#returnsarrayofGit::Commitobjectsg.log.since('2weeksago')g.log.between('v2.5','v2.6')g.log.each{|l|putsl.sha}g.gblob('v2.5:Makefile').log.since('2weeksago')g.object('HEAD^').to_s#gitshow/gitrev-parseg.object('HEAD^').contentsg.object('v2.5:Makefile').sizeg.object('v2.5:Makefile').shag.gtree(treeish)g.gblob(treeish)g.gcommit(treeish)commit=g.gcommit('1cc8667014381')commit.gtreecommit.parent.shacommit.parents.sizecommit.author.namecommit.author.emailcommit.author.date.strftime("%m-%d-%y")commit.committer.namecommit.date.strftime("%m-%d-%y")commit.messagetree=g.gtree("HEAD^{tree}")tree.blobstree.subtreestree.children#blobsandsubtreesg.revparse('v2.5:Makefile')g.branches#returnsGit::Branchobjectsg.branches.localg.branches.remoteg.branches[:master].gcommitg.branches['origin/master'].gcommitg.grep('hello')#impliesHEADg.blob('v2.5:Makefile').grep('hello')g.tag('v2.5').grep('hello','docs/')g.diff(commit1,commit2).sizeg.diff(commit1,commit2).statsg.gtree('v2.5').diff('v2.6').insertionsg.diff('gitsearch1','v2.5').path('lib/')g.diff('gitsearch1',@git.gtree('v2.5'))g.diff('gitsearch1','v2.5').path('docs/').patchg.gtree('v2.5').diff('v2.6').patchg.gtree('v2.5').diff('v2.6').eachdo|file_diff|putsfile_diff.pathputsfile_diff.patchputsfile_diff.blob(:src).contentsendg.config('user.name')#returns'ScottChacon'g.config#returnswholeconfighashg.tag#returnsarrayofGit::Tagobjects
评论