共計(jì) 1792 個(gè)字符,預(yù)計(jì)需要花費(fèi) 5 分鐘才能閱讀完成。
這篇文章主要介紹了 Rugged::Commit 類怎么使用的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇 Rugged::Commit 類怎么使用文章都會(huì)有所收獲,下面我們一起來看看吧。
1. 遍歷倉(cāng)庫(kù)的 Commits
Rugged::Walker 是用來對(duì)倉(cāng)庫(kù)的 commits 集合進(jìn)行遍歷的。
walker = Rugged::Walker.new(repo) #c
walker.sorting(Rugged::SORT_TOPO | Rugged::SORT_REVERSE) # 遍歷方式(按拓?fù)淠嫘颍部梢圆捎脮r(shí)間順序)walker.push(hex_sha_interesting) # 感興趣的 commit 的 oid(sha) 值, 從該 sha 開始進(jìn)行遍歷
walker.hide(hex_sha_uninteresting) # 不希望遍歷的 sha(由此包括其前面的 sha)walker.each { |c| puts c.inspect } #遍歷輸出
walker.reset
2. 創(chuàng)建 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,#構(gòu)建的根樹
:update_ref = HEAD #需要更新的分支名
#= f148106ca58764adc93ad4e2d6b1d168422b9796 #返回值,創(chuàng)建的 commit sha 值(oid)
3. 獲取 Commit 的相關(guān)屬性和目錄,文件以及 submodule
lastest_cmt = repo.head.target# 獲取 HEAD 指向的 Commit
root_tree = lastest_cmt.tree# 獲取根樹
entries = root_tree.entries#獲取根樹的文件和目錄(包括 submodule)列表
entries.each{|e|puts e}# 打印
#結(jié)果如下
{: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 從而得到文件大小和內(nèi)容
raw_blob.size # 文件大小
raw_blob.data# ascii 編碼內(nèi)容
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
關(guān)于“Rugged::Commit 類怎么使用”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Rugged::Commit 類怎么使用”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道。
正文完