2011-02-08 61 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