1

我正在使用 Grit 创建一个 repo 并提交几次。每次我提交时,我的提交都会保存,但旧的会消失。有人知道我做错了什么吗?

首先,我创建一个 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 log 时,只显示最后一次提交。以下行返回 1

repo.commits.count

知道我做错了什么吗?我真的找不到任何关于如何在 Grit 中使用 write 方法的教程。因此,任何链接也将不胜感激。谢谢!

4

1 回答 1

2

面团。答案很简单。提交号 2 需要将提交号 1 作为父级。然后它形成了这些提交的历史,并且它起作用了:

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

我仍在寻找解释 Grit 库中写入方法的教程或指南。rubyforge 文档没有解释太多。

于 2011-02-08T22:33:30.970 回答