【发布时间】:2015-04-06 10:41:16
【问题描述】:
我想在一个分支上进行提交(例如 master)。
我正在使用 pygit2 (pygit2.clone_repository) 进行存储库克隆
然后我更改存储库中的现有文件。
之后我运行它来提交:
index = repository.index
index.add_all()
index.write()
author = pygit2.Signature(user_name, user_mail)
commiter = pygit2.Signature(user_name, user_mail)
tree = repository.TreeBuilder().write()
oid = repository.create_commit(reference, author, commiter, message,tree,[repository.head.get_object().hex])
但是当我去存储库并运行git status:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: test.txt
修改后的文件似乎添加了提交,但提交没有成功。使用返回的 Oid 我可以在 pygit2 存储库中找到 commit 属性。
我错过了什么吗?
【问题讨论】:
-
我没有看到你的代码在某处提到了一个分支,也许你应该在某处指定它?
-
reference的值为'ref/heads/master'
-
我在为 pygit2 找到合适的文档时遇到了麻烦,所以我只是在猜测:我看到您在进行一些状态更改后调用了各种
write()方法。create_commit()是隐式写还是你忘记写了? -
我尝试在 create_commit 之后制作:repository.index.write_tree() 但我得到了相同的结果