浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Create a commit using pygit2

Create a commit using pygit2

I would like to make a commit on a branch (master for example).

I am making a repository clone using pygit2 (pygit2.clone_repository)

Then I change an existing file in the repository.

Afterwards I run this to make a commit:

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])

But when i go to the repository and run git status:

On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file:   test.txt

The modified file seems to be added for commit but the commit did not succeed. Using the returned Oid i can find the commit attribute in the pygit2 repository.

Did I miss something ?

使用 pygit2 创建提交 - ChaunceyHao - 博客园

posted on 2016-03-17 10:14  lexus  阅读(230)  评论(0编辑  收藏  举报