gpt4 book ai didi

ruby - 关于 Grit 的几个问题

转载 作者:数据小太阳 更新时间:2023-10-29 08:41:00 25 4
gpt4 key购买 nike

我有几个关于 Grit/Git 的问题,希望你能帮助我。这是我的代码:

# create Repo
r = Repo.init_bare 'myrepo.git'
i = r.index

# first commit to master
i.add('myfile.txt', 'my file contents')
i.commit("This is my commit")

# second commit to master
i.read_tree("master")
i.add('myfile2.txt', 'my file 2 contents')
i.commit("This is my second commit", [r.commits.first])

# first commit to newbranch
i.read_tree("master")
i.add('myfile3.txt', 'my file 3 contents')
i.commit("This is my third commit", [r.commits.first], nil, nil, 'newbranch')

# second commit to newbranch
i.read_tree("newbranch")
i.add('myfile4.txt', 'my file 4 contents')
i.commit("This is my fourth commit", [r.commit("newbranch")], nil, nil, 'newbranch')

使用这段代码,我尝试创建一个 repo,向 master 提交两次,从 master 创建一个新分支,然后向该分支提交两次。但问题是,当我这样做时:

r.commits("newbranch")  # => 3

它说“newbranch”上只有 3 个提交。它省略了对 master 的第二次提交。这是为什么?我的代码有问题吗?

我最困惑的是如何在分支时指定父提交,以及在“newbranch”上进行第二次提交时。

希望能帮到你。谢谢

最佳答案

API.txt 文件说这还没有实现为本地库实现。但是,您仍然可以这样做,绕过任何库实现,使用:

r.git.native :checkout, {}, 'my_branch'

查看 Grit 源的 git.rb 以获取更多详细信息。

关于ruby - 关于 Grit 的几个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5839106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com