1

我想克隆一个存储库,更改一个文件并将这些更改的文件推回原始分支。我可以克隆回购

repo = pygit2.clone_repository(repo_url, local_dir, checkout_branch="test_it")

但是我现在需要做什么才能将更改推送到遥控器?我只想提交一个特定文件的更改,即使更改了更多文件。

希望可以有人帮帮我。TIA

4

1 回答 1

1

仅第一阶段file_path

# stage 'file_path'
index = repository.index
index.add(file_path)
index.write()

然后做一个提交:

# commit data
reference='refs/HEAD'
message = '...some commit message...'
tree = index.write_tree()
author = pygit2.Signature(user_name, user_mail)
commiter = pygit2.Signature(user_name, user_mail)
oid = repository.create_commit(reference, author, commiter, message, tree, [repository.head.get_object().hex])

并按照Unable to ssh push in pygit2中的描述最后推送 repo

于 2016-06-01T21:46:11.593 回答