【问题标题】:How do i push to remote with pygit2?如何使用 pygit2 推送到远程?
【发布时间】:2016-02-19 18:52:54
【问题描述】:

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

克隆回购
repo = pygit2.clone_repository(repo_url, local_dir, checkout_branch="test_it")

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

希望有人可以帮助我。 TIA

【问题讨论】:

    标签: python pygit2


    【解决方案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中的描述推送回购

    【讨论】:

      猜你喜欢
      • 2012-06-09
      • 2010-10-31
      • 2016-10-07
      • 1970-01-01
      • 2014-08-30
      • 2012-07-08
      • 1970-01-01
      • 2011-07-08
      • 2014-06-05
      相关资源
      最近更新 更多