温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Rugged::Commit类怎么使用

发布时间:2022-01-14 15:28:54 来源:亿速云 阅读:122 作者:iii 栏目:云计算

这篇文章主要介绍了Rugged::Commit类怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Rugged::Commit类怎么使用文章都会有所收获,下面我们一起来看看吧。

    1.遍历仓库的Commits

        Rugged::Walker是用来对仓库的commits集合进行遍历的。

walker = Rugged::Walker.new(repo) #c
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) #遍历方式(按拓扑逆序,也可以采用时间顺序)
walker.push(hex_sha_interesting) #感兴趣的commit的oid(sha)值,从该sha开始进行遍历
walker.hide(hex_sha_uninteresting) #不希望遍历的sha(由此包括其前面的sha)
walker.each { |c| puts c.inspect }  #遍历输出
walker.reset

    2.创建Commit

author = {:email=>"zouqilin@csu.edu.cn", :time=>Time.now, :name=>"zouqilin"}#代码作者
committer = {:email=>"zouqilin@csu.edu.cn", :time=>Time.now, :name=>"zouqilin"}#提交者

Rugged::Commit.create(r,
    :author => author,
    :message => "Hello world\n\n",#提交信息
    :committer => author,
    :parents => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1"],#父提交
    :tree => some_tree,#构建的根树
    :update_ref => "HEAD"#需要更新的分支名
#=> "f148106ca58764adc93ad4e2d6b1d168422b9796"#返回值,创建的commit sha值(oid)

    3.获取Commit的相关属性和目录,文件以及submodule

lastest_cmt = repo.head.target#获取HEAD指向的Commit
root_tree = lastest_cmt.tree#获取根树
entries = root_tree.entries#获取根树的文件和目录(包括submodule)列表
entries.each{|e|puts e}#打印
#结果如下
{:type=>:blob, :oid=>"99e7edb53db9355f10c6f2dfaa5a183f205d93bf", :filemode=>100644, :name=>".gitignore"}
{ :type => :tree, :name => "lib", :oid => "e1253910439ea902cf49be8a9f02f3c08d89ac73", :filemode => 040000 }
{ :type => :blob, :name => "README.md", :oid => "81b68f040b120c9627518213f7fc317d1ed18e1c", :filemode => 0100644 }

raw_blob = repo.lookup("81b68f040b120c9627518213f7fc317d1ed18e1c")#获取raw_blob从而得到文件大小和内容
raw_blob.size #文件大小
raw_blob.data# ascii编码内容
raw_blob.text#utf-8文本

raw_tree = repo.lookup("e1253910439ea902cf49be8a9f02f3c08d89ac73")
raw.entries#目录下的entry
raw.count#目录下的entries count
raw.path("lib/string.h")#获取string.h的entry

关于“Rugged::Commit类怎么使用”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Rugged::Commit类怎么使用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI