2011-02-08 86 views
1

我用砂創建一個回購協議,並承諾儘可能少的時間。每次我提交時,我的提交都會保存,但是舊提交會消失。任何人有任何線索我做錯了什麼?Grit commit似乎在壓倒Git repo的最後一次提交?

首先我創建了一個回購協議,並作出承諾。如果我登錄提交,我得到的提交ID,和一切工作

repo_name = 'repos/myrepo.git' 
repo = Repo.init_bare(repo_name) 
index = Index.new(repo) 
index.add('mytext.txt', "This is my first text") 
index.commit('Text commit') 

那我另一個承諾

index = repo.index 
index.read_tree('master') 
index.add('mytext.txt', "This is my second text") 
index.commit('Text commit') 

..而當我做了git的日誌,只有最後提交顯示出來。以下行返回1

repo.commits.count 

任何想法我做錯了什麼?我找不到任何有關如何在Grit中使用寫入方法的教程。所以任何鏈接也將不勝感激。謝謝!

回答

2

麪糰。答案很簡單。提交號碼2需要提交號碼1作爲父代。然後,它形成這些提交的歷史,它的工作原理:

index.commit('Text commit', [repo.commits.first]) 

我還在找教程或導遊介紹在砂庫中的寫入方法。 rubyforge文檔沒有太多解釋。

+1

你可能有一個看看Git是自己的手冊(http://www.kernel.org/pub/software/scm/git/docs/),尤其是「管道」的命令。它們中的大多數在Grit的API中使用或多或少相同。 等效於例如`砂礫::指數#commit`是'混帳提交 - tree`(http://www.kernel.org/pub/software/scm/git/docs/v1.7.4/git-commit-tree.html)。 – Koraktor 2011-02-08 22:39:19