Python 使用pygit2提交时未跟踪的目录

Python 使用pygit2提交时未跟踪的目录,python,git,libgit2,pygit2,Python,Git,Libgit2,Pygit2,我正在使用pygit2开发一个非裸存储库 index = repo.index index.read() # write in test/test.txt index.add('test/test.txt') treeid = index.write_tree() repo.create_commit( 'HEAD', author, committer, 'test commit', treeid, [repo.head.oid] ) 这是成功的

我正在使用pygit2开发一个非裸存储库

index = repo.index
index.read()

# write in test/test.txt

index.add('test/test.txt')
treeid = index.write_tree()

repo.create_commit(
    'HEAD',
    author, committer,
    'test commit',
    treeid,
    [repo.head.oid]
)
这是成功的,但是当我执行一个
git状态时,我得到了以下结果:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    test/test.txt
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   test/
分支主机上的
#
#要提交的更改:
#(使用“git重置磁头…”取消分级)
#
#已删除:test/test.txt
#
#未跟踪的文件:
#(使用“git add…”包含在将提交的内容中)
#
#试验/
在git重设--hard之后,一切都被修复了


有没有办法用pygit正确更新索引?

您只是从内存索引中写出一棵树,而不修改磁盘索引,因此在提交后,它的状态与执行任何操作之前相同

如果希望将更改存储在光盘上,则需要写出索引(
index.write()