溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Rugged::Commit類怎么使用

發(fā)布時間:2022-01-14 15:28:54 來源:億速云 閱讀:124 作者: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.創(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,#構建的根樹
    :update_ref => "HEAD"#需要更新的分支名
#=> "f148106ca58764adc93ad4e2d6b1d168422b9796"#返回值,創(chuàng)建的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類怎么使用”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI