2016-02-19 46 views
0

我想克隆一個存儲庫,更改文件並將這些已更改的文件推回到原始分支。 我可以克隆與如何使用pygit2推送到遠程?

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

但回購什麼我現在需要做的推更改遠程?我只想提交一個特定文件的更改,即使更多文件被更改。

希望有人能幫助我。 TIA

回答

0

第一階段只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

描述