Rugged::Commit类怎么使用

52次阅读
没有评论

共计 1792 个字符,预计需要花费 5 分钟才能阅读完成。

这篇文章主要介绍了 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 类怎么使用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-04发表,共计1792字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)