1

i want to clone a repository, change a file and push these changed file back to the origin branch. I can clone the repo with

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

but what do i need to do now to push the changes to the remote? I want only commit the changes for one specific file, even if more files are changed.

Hope someone can help me. TIA

topic2k
  • 11
  • 1
  • 2
  • 5

1 Answers1

0

First stage only file_path:

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

Then do a commit:

# 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])

and last push the repo as described in Unable to ssh push in pygit2

Community
  • 1
  • 1
mrh1997
  • 922
  • 7
  • 18