5

私は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 statusようになりました。

# 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 reset --hard、すべてが修正されます。

pygit でインデックスを正しく更新する方法はありますか?

4

1 に答える 1

7

メモリ内インデックスからツリーを書き出すだけで、ディスク上のインデックスは変更されないため、コミット後は何かを行う前と同じ状態になります。

index.write()変更をディスクに保存する場合は、インデックス ( ) を書き出す必要があります。

于 2013-04-17T10:01:19.413 に答える