1

I'm a little confused about how to get started with PyGit2.

When adding files (plural) to a newly created repo, should I add them to index.add('path/to/file')
or would I be better off creating a TreeBuilder and using tb.insert( 'name',oid, GIT_FILEMODE_BLOB ) to add new content ?

If the second case, I am stumped as to how I create the tree object needed to commit to a newly created repo?

Anyone?

4

2 に答える 2

0

pygit2.Repositoryあなたが呼ばれると仮定してrepo、試してください:

t_builder = repo.TreeBuilder()

help(pygit2.TreeBuilder)Python コンソールからのより便利な情報。

于 2014-01-24T10:39:19.860 に答える
0

どちらの方法でも実行できます。
方法は簡単だと思いますindex.add()

Repository.status() ディクショナリとして使用して、インデックスに追加または削除するすべてのファイルを取得できます 。ディクショナリには、キーとしてファイル名、値としてファイルのステータスが含まれます。ステータス値によっては、削除されたファイルを を使用してインデックスから削除する必要がありますindex.remove(filename)
このインデックスをインメモリ ツリーに書き込みます。これindex.write_tree()は、で使用されるツリー ID を返しRepository.commit()ます。ただし、変更をディスクに保存する場合も使用しindex.write()ます。

于 2014-07-12T05:57:16.250 に答える